Skip to content

Commit

Permalink
fix: fixed 500 status for algolia dontBatch (#3178)
Browse files Browse the repository at this point in the history
* fix: fixed 500 for algolia dontBatch
  • Loading branch information
aashishmalik authored Mar 14, 2024
1 parent a31d93c commit 6330888
Showing 1 changed file with 7 additions and 24 deletions.
31 changes: 7 additions & 24 deletions src/v1/destinations/algolia/networkHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ const responseHandler = (responseParams) => {
const { destinationResponse, rudderJobMetadata } = responseParams;
const message = `[ALGOLIA Response V1 Handler] - Request Processed Successfully`;
const responseWithIndividualEvents = [];
// response:
// {status: 200, message: 'OK'}
// {response:'[ENOTFOUND] :: DNS lookup failed', status: 400}
// destinationResponse = {
// response: {"status": 422, "message": "EventType must be one of \"click\", \"conversion\" or \"view\""}, status: 422
// }
const { response, status } = destinationResponse;

if (isHttpStatusSuccess(status)) {
Expand All @@ -41,30 +35,19 @@ const responseHandler = (responseParams) => {

// in case of non 2xx status sending 500 for every event, populate response and update dontBatch to true
const errorMessage = response?.error?.message || response?.message || 'unknown error format';
let serverStatus = 400;
for (const metadata of rudderJobMetadata) {
// handling case if dontBatch is true, and again we got invalid from destination
if (metadata.dontBatch && status === 422) {
responseWithIndividualEvents.push({
statusCode: 400,
metadata,
error: errorMessage,
});
} else {
serverStatus = 500;
metadata.dontBatch = true;
responseWithIndividualEvents.push({
statusCode: 500,
metadata,
error: errorMessage,
});
}
metadata.dontBatch = true;
responseWithIndividualEvents.push({
statusCode: 500,
metadata,
error: errorMessage,
});
}

// sending back 500 for retry
throw new TransformerProxyError(
`ALGOLIA: Error transformer proxy v1 during ALGOLIA response transformation`,
serverStatus,
500,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(status),
},
Expand Down

0 comments on commit 6330888

Please sign in to comment.