Skip to content

Commit 31d57e2

Browse files
yashasvibajpaiSai Sankeerth
and
Sai Sankeerth
authored
chore: handle other error use-cases in reddit (#3692)
* chore: add logger for reddit in case of non 401 status * chore: handle other error use-cases in reddit * chore: fix test for reddit * chore: add test --------- Co-authored-by: Sai Sankeerth <[email protected]>
1 parent c024eee commit 31d57e2

File tree

3 files changed

+124
-5
lines changed

3 files changed

+124
-5
lines changed

src/v0/destinations/reddit/networkHandler.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
const { RetryableError } = require('@rudderstack/integrations-lib');
1+
const { RetryableError, TAG_NAMES, NetworkError } = require('@rudderstack/integrations-lib');
22
const isString = require('lodash/isString');
33
const { prepareProxyRequest, proxyRequest } = require('../../../adapters/network');
44
const { isHttpStatusSuccess } = require('../../util/index');
55
const { REFRESH_TOKEN } = require('../../../adapters/networkhandler/authConstants');
66

7-
const { processAxiosResponse } = require('../../../adapters/utils/networkUtils');
7+
const {
8+
processAxiosResponse,
9+
getDynamicErrorType,
10+
} = require('../../../adapters/utils/networkUtils');
811

912
const redditRespHandler = (destResponse) => {
1013
const { status, response } = destResponse;
@@ -29,6 +32,14 @@ const redditRespHandler = (destResponse) => {
2932
authErrorCategory,
3033
);
3134
}
35+
throw new NetworkError(
36+
`${JSON.stringify(response)} during reddit response transformation`,
37+
status,
38+
{
39+
[TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(status),
40+
},
41+
destResponse,
42+
);
3243
};
3344
const responseHandler = (responseParams) => {
3445
const { destinationResponse } = responseParams;

test/integrations/destinations/reddit/dataDelivery/business.ts

+55-3
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export const testScenariosForV1API = [
103103
body: generateProxyV1Payload(
104104
{
105105
...commonRequestParameters,
106-
endpoint: 'https://dfareporting.googleapis.com/test_url_for_valid_request',
106+
endpoint: 'https://ads-api.reddit.com/api/v2.0/conversions/events/a2_fsddXXXfsfd',
107107
},
108108
[generateMetadata(1)],
109109
),
@@ -119,10 +119,62 @@ export const testScenariosForV1API = [
119119
response: [
120120
{
121121
metadata: generateMetadata(1),
122-
statusCode: 500,
122+
statusCode: 200,
123123
},
124124
],
125-
status: 500,
125+
status: 200,
126+
},
127+
},
128+
},
129+
},
130+
},
131+
{
132+
id: 'reddit_v1_scenario_2',
133+
name: 'reddit',
134+
description:
135+
'[Proxy v1 API] :: Test for a valid request with a failed 403 response from the destination',
136+
scenario: 'Business',
137+
feature: 'dataDelivery',
138+
module: 'destination',
139+
version: 'v1',
140+
input: {
141+
request: {
142+
body: generateProxyV1Payload(
143+
{
144+
...commonRequestParameters,
145+
endpoint: 'https://ads-api.reddit.com/api/v2.0/conversions/events/403_event',
146+
},
147+
[generateMetadata(1)],
148+
),
149+
method: 'POST',
150+
},
151+
},
152+
output: {
153+
response: {
154+
status: 200,
155+
body: {
156+
output: {
157+
message:
158+
'{"success":false,"error":{"reason":"UNAUTHORIZED","explanation":"JSON error unexpected type number on field events event_metadata value"}} during reddit response transformation',
159+
response: [
160+
{
161+
metadata: generateMetadata(1),
162+
statusCode: 403,
163+
error:
164+
'{"success":false,"error":{"reason":"UNAUTHORIZED","explanation":"JSON error unexpected type number on field events event_metadata value"}}',
165+
},
166+
],
167+
statTags: {
168+
destType: 'REDDIT',
169+
destinationId: 'default-destinationId',
170+
errorCategory: 'network',
171+
errorType: 'aborted',
172+
feature: 'dataDelivery',
173+
implementation: 'native',
174+
module: 'destination',
175+
workspaceId: 'default-workspaceId',
176+
},
177+
status: 403,
126178
},
127179
},
128180
},

test/integrations/destinations/reddit/network.ts

+56
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,60 @@ export const networkCallsData = [
154154
statusText: 'Unauthorized',
155155
},
156156
},
157+
{
158+
httpReq: {
159+
url: 'https://ads-api.reddit.com/api/v2.0/conversions/events/403_event',
160+
data: {
161+
events: [
162+
{
163+
event_at: '2019-10-14T09:03:17.562Z',
164+
event_type: {
165+
tracking_type: 'Purchase',
166+
},
167+
user: {
168+
aaid: 'c12d34889302d3c656b5699fa9190b51c50d6f62fce57e13bd56b503d66c487a',
169+
email: 'ac144532d9e4efeab19475d9253a879173ea12a3d2238d1cb8a332a7b3a105f2',
170+
external_id: '7b023241a3132b792a5a33915a5afb3133cbb1e13d72879689bf6504de3b036d',
171+
ip_address: 'e80bd55a3834b7c2a34ade23c7ecb54d2a49838227080f50716151e765a619db',
172+
user_agent:
173+
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36',
174+
screen_dimensions: {},
175+
},
176+
event_metadata: {
177+
item_count: 3,
178+
products: [
179+
{
180+
id: '123',
181+
name: 'Monopoly',
182+
category: 'Games',
183+
},
184+
{
185+
id: '345',
186+
name: 'UNO',
187+
category: 'Games',
188+
},
189+
],
190+
},
191+
},
192+
],
193+
},
194+
params: { destination: 'reddit' },
195+
headers: {
196+
Authorization: 'Bearer dummyAccessToken',
197+
'Content-Type': 'application/json',
198+
},
199+
method: 'POST',
200+
},
201+
httpRes: {
202+
data: {
203+
success: false,
204+
error: {
205+
reason: 'UNAUTHORIZED',
206+
explanation: 'JSON error unexpected type number on field events event_metadata value',
207+
},
208+
},
209+
status: 403,
210+
statusText: 'Unauthorized',
211+
},
212+
},
157213
];

0 commit comments

Comments
 (0)