Skip to content

Commit

Permalink
fix: update error handling logic for unauthorised case
Browse files Browse the repository at this point in the history
- new error response handled
- backward compatibility
  • Loading branch information
Sai Sankeerth committed Aug 29, 2024
1 parent 7cb7162 commit 38886d6
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/v0/destinations/reddit/networkHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,25 @@ const redditRespHandler = (destResponse) => {
const { status, response } = destResponse;

// to handle the case when authorization-token is invalid
if (status === 401 && isString(response) && response.includes('Authorization Required')) {
if (status === 401) {
let errorMessage = 'Authorization failed';
let errorDetails = response;
let authErrorCategory = '';

if (isString(response) && response.includes('Authorization Required')) {
errorMessage = `Request failed due to ${response}`;
authErrorCategory = REFRESH_TOKEN;
} else if (response?.error?.reason === 'UNAUTHORIZED') {
errorMessage = response.error.explanation || errorMessage;
errorDetails = response.error;
authErrorCategory = REFRESH_TOKEN;

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

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/reddit/networkHandler.js#L23-L24

Added lines #L23 - L24 were not covered by tests
}

throw new RetryableError(
`Request failed due to ${response} 'during reddit response transformation'`,
500,
destResponse,
REFRESH_TOKEN,
`${errorMessage} 'during reddit response transformation'`,
status,
errorDetails,
authErrorCategory,
);
}
};
Expand Down

0 comments on commit 38886d6

Please sign in to comment.