diff --git a/references/common-shared-flows/error-handling-v1/sharedflowbundle/resources/jsc/PopulateDefaultErrorVariables.js b/references/common-shared-flows/error-handling-v1/sharedflowbundle/resources/jsc/PopulateDefaultErrorVariables.js index d00705ae2..aca1b6f98 100644 --- a/references/common-shared-flows/error-handling-v1/sharedflowbundle/resources/jsc/PopulateDefaultErrorVariables.js +++ b/references/common-shared-flows/error-handling-v1/sharedflowbundle/resources/jsc/PopulateDefaultErrorVariables.js @@ -35,27 +35,69 @@ function setFault(status, phrase, code, message, url) { } switch (context.getVariable("fault.name")) { + //400 Bad Request + case "ExceededContainerDepth": + case "ExceededObjectEntryCount": + case "ExceededArrayElementCount": + case "ExceededObjectEntryNameLength": + case "ExceededStringValueLength": + case "SourceUnavailable": + case "NonMessageVariable": + case "ExecutionFailed": + case "ThreatDetected": + setFault(400,"Bad Request","400.99","Bad Request"); + break; + + //401 Unauthorized + case "ApiKeyNotApproved": + case "CompanyStatusNotActive": + case "DeveloperStatusNotActive": + case "FailedToResolveAPIKey": + case "InvalidApiKey": + case "InvalidApiKeyForGivenResource": + case "InvalidAPICallAsNoApiProductMatchFound": + case "app_not_approved": + case "FailedToResolveAccessToken": + case "FailedToResolveToken": + case "FailedToResolveAuthorizationCode": + case "InvalidAccessToken": case "access_token_expired": case "invalid_access_token": - case "InvalidAccessToken": - setFault( - 401, - "Unauthorized", - "401.99", - "Unauthorized - Token Invalid or Expired" - ); + case "InvalidOperation": + setFault(401,"Unauthorized","401.99","Unauthorized - Token Invalid or Expired"); + break; + + //403 Forbidden + case "InsufficientScope": + setFault(403,"Forbidden","403.99","Forbidden"); break; + + //429 Too Many Requests + case "SpikeArrestViolation": + case "InvalidMessageWeight": + case "ErrorLoadingProperties": + case "FailedToResolveSpikeArrestRate": + case "QuotaViolation": + case "InvalidQuotaInterval": + case "InvalidQuotaTimeUnit": + case "FailedToResolveQuotaIntervalReference": + case "FailedToResolveQuotaIntervalTimeUnitReference": + setFault(429,"Too Many Requests","429.99","Too Many Requests"); + break; + case "ErrorResponseCode": - switch (context.getVariable("response.status.code")) { - case "400": - setFault(400, "Bad Request", "400.99", "Invalid Request"); - break; - case "404": - setFault(404, "Resource Not Found", "404.99", "Resource Not Found"); - break; - } + setFault(context.getVariable("error.status.code"),context.getVariable("error.status.phrase"),context.getVariable("error.status.code")+".99",context.getVariable("error.status.phrase")); + break; + // switch (context.getVariable("response.status.code")) { + // case "400": + // setFault(400, "Bad Request", "400.99", "Invalid Request"); + // break; + // case "404": + // setFault(404, "Resource Not Found", "404.99", "Resource Not Found"); + // break; + // } } -if (!context.getVariable("custom.error.code")) { +if (context.getVariable("flow.error.code") == null || !context.getVariable("custom.error.code")) { setFault(500, "Internal Server Error", "500.99", "Internal Server Error"); }