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

fix: adding throttled status code for server unavailable error in salesforce #3862

Merged
merged 5 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
45 changes: 36 additions & 9 deletions src/v0/destinations/salesforce/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,29 @@ const {

const ACCESS_TOKEN_CACHE = new Cache(ACCESS_TOKEN_CACHE_TTL);

/**
* Extracts and returns the error message from a response object.
* If the response is an array and contains a message in the first element,
* it returns that message. Otherwise, it returns the stringified response.
* Error Message Format Example: ref: https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/errorcodes.htm#:~:text=Incorrect%20ID%20example
[
{
"fields" : [ "Id" ],
"message" : "Account ID: id value of incorrect type: 001900K0001pPuOAAU",
"errorCode" : "MALFORMED_ID"
}
]
* @param {Object|Array} response - The response object or array to extract the message from.
* @returns {string} The extracted error message or the stringified response.
*/

const getErrorMessage = (response) => {
utsabc marked this conversation as resolved.
Show resolved Hide resolved
if (Array.isArray(response) && response?.[0]?.message && response?.[0]?.message?.length > 0) {
return response[0].message;
}
return JSON.stringify(response);
};

/**
* ref: https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/errorcodes.htm
* handles Salesforce application level failures
Expand Down Expand Up @@ -77,15 +100,19 @@ const salesforceResponseHandler = (destResponse, sourceMessage, authKey, authori
} else if (status === 503 || status === 500) {
// The salesforce server is unavailable to handle the request. Typically this occurs if the server is down
// for maintenance or is currently overloaded.
throw new RetryableError(
`${DESTINATION} Request Failed - due to "${
response && Array.isArray(response) && response[0]?.message?.length > 0
? response[0].message
: JSON.stringify(response)
}", (Retryable) ${sourceMessage}`,
500,
destResponse,
);
// ref : https://help.salesforce.com/s/articleView?id=000387190&type=1
if (matchErrorCode('SERVER_UNAVAILABLE')) {
utsabc marked this conversation as resolved.
Show resolved Hide resolved
throw new ThrottledError(
`${DESTINATION} Request Failed: ${status} - due to Search unavailable, ${sourceMessage}`,
shrouti1507 marked this conversation as resolved.
Show resolved Hide resolved
destResponse,
);
} else {
throw new RetryableError(
`${DESTINATION} Request Failed: ${status} - due to "${getErrorMessage(response)}", (Retryable) ${sourceMessage}`,
500,
destResponse,
);
}
}
// check the error message
let errorMessage = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export const testScenariosForV1API: ProxyV1TestData[] = [
output: {
status: 500,
message:
'Salesforce Request Failed - due to "Session expired or invalid", (Retryable) during Salesforce Response Handling',
'Salesforce Request Failed: 500 - due to "Session expired or invalid", (Retryable) during Salesforce Response Handling',
response: [
{
error:
Expand Down Expand Up @@ -277,16 +277,16 @@ export const testScenariosForV1API: ProxyV1TestData[] = [
body: {
output: {
message:
'Salesforce Request Failed - due to "Server Unavailable", (Retryable) during Salesforce Response Handling',
'Salesforce Request Failed: 503 - due to Search unavailable, during Salesforce Response Handling',
response: [
{
error: '[{"message":"Server Unavailable","errorCode":"SERVER_UNAVAILABLE"}]',
metadata: proxyMetdata,
statusCode: 500,
statusCode: 429,
},
],
statTags: statTags.retryable,
status: 500,
statTags: statTags.throttled,
status: 429,
},
},
},
Expand Down
14 changes: 7 additions & 7 deletions test/integrations/destinations/salesforce/dataDelivery/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,12 @@ const legacyTests = [
},
output: {
response: {
status: 500,
status: 429,
body: {
output: {
status: 500,
status: 429,
message:
'Salesforce Request Failed - due to "Server Unavailable", (Retryable) during Salesforce Response Handling',
'Salesforce Request Failed: 503 - due to Search unavailable, during Salesforce Response Handling',
destinationResponse: {
response: [
{
Expand All @@ -334,7 +334,7 @@ const legacyTests = [
errorCategory: 'network',
destinationId: 'Non-determininable',
workspaceId: 'Non-determininable',
errorType: 'retryable',
errorType: 'throttled',
feature: 'dataDelivery',
implementation: 'native',
module: 'destination',
Expand Down Expand Up @@ -461,7 +461,7 @@ const legacyTests = [
status: 503,
},
message:
'Salesforce Request Failed - due to "{"message":"Server Unavailable","errorCode":"SERVER_UNAVAILABLE"}", (Retryable) during Salesforce Response Handling',
'Salesforce Request Failed: 503 - due to "{"message":"Server Unavailable","errorCode":"SERVER_UNAVAILABLE"}", (Retryable) during Salesforce Response Handling',
statTags: {
destType: 'SALESFORCE',
errorCategory: 'network',
Expand Down Expand Up @@ -603,7 +603,7 @@ const legacyTests = [
output: {
status: 500,
message:
'Salesforce Request Failed - due to ""[ECONNABORTED] :: Connection aborted"", (Retryable) during Salesforce Response Handling',
'Salesforce Request Failed: 500 - due to ""[ECONNABORTED] :: Connection aborted"", (Retryable) during Salesforce Response Handling',
destinationResponse: {
response: '[ECONNABORTED] :: Connection aborted',
status: 500,
Expand Down Expand Up @@ -696,7 +696,7 @@ const legacyTests = [
output: {
status: 500,
message:
'Salesforce Request Failed - due to ""[EAI_AGAIN] :: Temporary failure in name resolution"", (Retryable) during Salesforce Response Handling',
'Salesforce Request Failed: 500 - due to ""[EAI_AGAIN] :: Temporary failure in name resolution"", (Retryable) during Salesforce Response Handling',
destinationResponse: {
response: '[EAI_AGAIN] :: Temporary failure in name resolution',
status: 500,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const otherSalesforceScenariosV1: ProxyV1TestData[] = [
],
statTags,
message:
'Salesforce Request Failed - due to "{"error":{"message":"Service Unavailable","description":"The server is currently unable to handle the request due to temporary overloading or maintenance of the server. Please try again later."}}", (Retryable) during Salesforce Response Handling',
'Salesforce Request Failed: 503 - due to "{"error":{"message":"Service Unavailable","description":"The server is currently unable to handle the request due to temporary overloading or maintenance of the server. Please try again later."}}", (Retryable) during Salesforce Response Handling',
status: 500,
},
},
Expand Down Expand Up @@ -96,7 +96,7 @@ export const otherSalesforceScenariosV1: ProxyV1TestData[] = [
],
statTags,
message:
'Salesforce Request Failed - due to ""Internal Server Error"", (Retryable) during Salesforce Response Handling',
'Salesforce Request Failed: 500 - due to ""Internal Server Error"", (Retryable) during Salesforce Response Handling',
status: 500,
},
},
Expand Down
Loading