Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: handle other error use-cases in reddit (#3692) #3700

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/v0/destinations/reddit/networkHandler.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
const { RetryableError } = require('@rudderstack/integrations-lib');
const { RetryableError, TAG_NAMES, NetworkError } = require('@rudderstack/integrations-lib');
const isString = require('lodash/isString');
const { prepareProxyRequest, proxyRequest } = require('../../../adapters/network');
const { isHttpStatusSuccess } = require('../../util/index');
const { REFRESH_TOKEN } = require('../../../adapters/networkhandler/authConstants');

const { processAxiosResponse } = require('../../../adapters/utils/networkUtils');
const {
processAxiosResponse,
getDynamicErrorType,
} = require('../../../adapters/utils/networkUtils');

const redditRespHandler = (destResponse) => {
const { status, response } = destResponse;
Expand All @@ -29,6 +32,14 @@
authErrorCategory,
);
}
throw new NetworkError(

Check warning on line 35 in src/v0/destinations/reddit/networkHandler.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/reddit/networkHandler.js#L35

Added line #L35 was not covered by tests
`${JSON.stringify(response)} during reddit response transformation`,
status,
{
[TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(status),
},
destResponse,
);
};
const responseHandler = (responseParams) => {
const { destinationResponse } = responseParams;
Expand Down
58 changes: 55 additions & 3 deletions test/integrations/destinations/reddit/dataDelivery/business.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const testScenariosForV1API = [
body: generateProxyV1Payload(
{
...commonRequestParameters,
endpoint: 'https://dfareporting.googleapis.com/test_url_for_valid_request',
endpoint: 'https://ads-api.reddit.com/api/v2.0/conversions/events/a2_fsddXXXfsfd',
},
[generateMetadata(1)],
),
Expand All @@ -119,10 +119,62 @@ export const testScenariosForV1API = [
response: [
{
metadata: generateMetadata(1),
statusCode: 500,
statusCode: 200,
},
],
status: 500,
status: 200,
},
},
},
},
},
{
id: 'reddit_v1_scenario_2',
name: 'reddit',
description:
'[Proxy v1 API] :: Test for a valid request with a failed 403 response from the destination',
scenario: 'Business',
feature: 'dataDelivery',
module: 'destination',
version: 'v1',
input: {
request: {
body: generateProxyV1Payload(
{
...commonRequestParameters,
endpoint: 'https://ads-api.reddit.com/api/v2.0/conversions/events/403_event',
},
[generateMetadata(1)],
),
method: 'POST',
},
},
output: {
response: {
status: 200,
body: {
output: {
message:
'{"success":false,"error":{"reason":"UNAUTHORIZED","explanation":"JSON error unexpected type number on field events event_metadata value"}} during reddit response transformation',
response: [
{
metadata: generateMetadata(1),
statusCode: 403,
error:
'{"success":false,"error":{"reason":"UNAUTHORIZED","explanation":"JSON error unexpected type number on field events event_metadata value"}}',
},
],
statTags: {
destType: 'REDDIT',
destinationId: 'default-destinationId',
errorCategory: 'network',
errorType: 'aborted',
feature: 'dataDelivery',
implementation: 'native',
module: 'destination',
workspaceId: 'default-workspaceId',
},
status: 403,
},
},
},
Expand Down
56 changes: 56 additions & 0 deletions test/integrations/destinations/reddit/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,60 @@ export const networkCallsData = [
statusText: 'Unauthorized',
},
},
{
httpReq: {
url: 'https://ads-api.reddit.com/api/v2.0/conversions/events/403_event',
data: {
events: [
{
event_at: '2019-10-14T09:03:17.562Z',
event_type: {
tracking_type: 'Purchase',
},
user: {
aaid: 'c12d34889302d3c656b5699fa9190b51c50d6f62fce57e13bd56b503d66c487a',
email: 'ac144532d9e4efeab19475d9253a879173ea12a3d2238d1cb8a332a7b3a105f2',
external_id: '7b023241a3132b792a5a33915a5afb3133cbb1e13d72879689bf6504de3b036d',
ip_address: 'e80bd55a3834b7c2a34ade23c7ecb54d2a49838227080f50716151e765a619db',
user_agent:
'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',
screen_dimensions: {},
},
event_metadata: {
item_count: 3,
products: [
{
id: '123',
name: 'Monopoly',
category: 'Games',
},
{
id: '345',
name: 'UNO',
category: 'Games',
},
],
},
},
],
},
params: { destination: 'reddit' },
headers: {
Authorization: 'Bearer dummyAccessToken',
'Content-Type': 'application/json',
},
method: 'POST',
},
httpRes: {
data: {
success: false,
error: {
reason: 'UNAUTHORIZED',
explanation: 'JSON error unexpected type number on field events event_metadata value',
},
},
status: 403,
statusText: 'Unauthorized',
},
},
];
Loading