Skip to content

Commit

Permalink
Merge pull request #763 from ssvaidyanathan/main
Browse files Browse the repository at this point in the history
feat: adding more fault names to the sharedflow reference sample
  • Loading branch information
danistrebel authored Nov 20, 2024
2 parents 874853e + ed02c9c commit 893835e
Showing 1 changed file with 58 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

0 comments on commit 893835e

Please sign in to comment.