Skip to content

Commit

Permalink
fix: criteo_aud auth_token expire code incorporated (#2687)
Browse files Browse the repository at this point in the history
* fix: criteo_aud auth_token expire code incorporated

* test cases added
  • Loading branch information
anantjain45823 committed Oct 5, 2023
1 parent 6fc3d97 commit cbe333a
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/v0/destinations/criteo_audience/networkHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ const criteoAudienceRespHandler = (destResponse, stageMsg) => {

// https://developers.criteo.com/marketing-solutions/docs/api-error-types#error-category-types
// to handle the case when authorization-token is invalid
if (status === 401 && matchErrorCode('authorization-token-invalid', response)) {
if (
status === 401 &&
(matchErrorCode('authorization-token-invalid', response) ||
matchErrorCode('authorization-token-expired', response))
) {
throw new NetworkError(
`${response?.errors[0]?.title} ${stageMsg}`,
status,
Expand Down
17 changes: 17 additions & 0 deletions test/__mocks__/data/criteo_audience/proxy_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@
"https://api.criteo.com/2022-10/audiences/34894/contactlist": {
"status": 200
},
"https://api.criteo.com/2022-10/audiences/3485/contactlist": {
"code": "400",
"response": {
"data": {
"errors": [
{
"traceIdentifier": "80a1a0ba3981b04da847d05700752c77",
"type": "authorization",
"code": "authorization-token-expired",
"instance": "/2022-10/audiences/123/contactlist",
"title": "The authorization token has expired"
}
]
},
"status": 401
}
},
"https://api.criteo.com/2022-10/audiences/34895/contactlist": {
"code": "400",
"response": {
Expand Down
35 changes: 35 additions & 0 deletions test/__tests__/data/criteo_audience_proxy_input.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,41 @@
"destination": "criteo_audience"
}
},
{
"version": "1",
"type": "REST",
"method": "PATCH",
"endpoint": "https://api.criteo.com/2022-10/audiences/3485/contactlist",
"headers": {
"Authorization": "Bearer success_access_token",
"Content-Type": "application/json",
"Accept": "application/json"
},
"body": {
"JSON": {
"data": {
"type": "ContactlistAmendment",
"attributes": {
"operation": "add",
"identifierType": "madid",
"identifiers": [
"sample_madid",
"sample_madid_1",
"sample_madid_2"
],
"internalIdentifiers": false
}
}
},
"JSON_ARRAY": {},
"XML": {},
"FORM": {}
},
"files": {},
"params": {
"destination": "criteo_audience"
}
},
{
"version": "1",
"type": "REST",
Expand Down
32 changes: 30 additions & 2 deletions test/__tests__/data/criteo_audience_proxy_output.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[
{
{
"output": {
"status": 200,
"message": "Request Processed Successfully",
Expand All @@ -9,6 +9,34 @@
}
}
},
{
"output": {
"status": 401,
"authErrorCategory": "REFRESH_TOKEN",
"destinationResponse": {
"errors": [
{
"traceIdentifier": "80a1a0ba3981b04da847d05700752c77",
"type": "authorization",
"code": "authorization-token-expired",
"instance": "/2022-10/audiences/123/contactlist",
"title": "The authorization token has expired"
}
]
},
"message": "The authorization token has expired during criteo_audience response transformation",
"statTags": {
"destType": "CRITEO_AUDIENCE",
"errorCategory": "network",
"destinationId": "Non-determininable",
"workspaceId": "Non-determininable",
"errorType": "aborted",
"feature": "dataDelivery",
"implementation": "native",
"module": "destination"
}
}
},
{
"output": {
"status": 401,
Expand Down Expand Up @@ -48,7 +76,7 @@
"traceIdentifier": "80a1a0ba3981b04da847d05700752c77",
"type": "authorization"
}
]
]
},
"status": 404
},
Expand Down

0 comments on commit cbe333a

Please sign in to comment.