Skip to content

Commit 893835e

Browse files
authored
Merge pull request #763 from ssvaidyanathan/main
feat: adding more fault names to the sharedflow reference sample
2 parents 874853e + ed02c9c commit 893835e

File tree

1 file changed

+58
-16
lines changed

1 file changed

+58
-16
lines changed

references/common-shared-flows/error-handling-v1/sharedflowbundle/resources/jsc/PopulateDefaultErrorVariables.js

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,69 @@ function setFault(status, phrase, code, message, url) {
3535
}
3636

3737
switch (context.getVariable("fault.name")) {
38+
//400 Bad Request
39+
case "ExceededContainerDepth":
40+
case "ExceededObjectEntryCount":
41+
case "ExceededArrayElementCount":
42+
case "ExceededObjectEntryNameLength":
43+
case "ExceededStringValueLength":
44+
case "SourceUnavailable":
45+
case "NonMessageVariable":
46+
case "ExecutionFailed":
47+
case "ThreatDetected":
48+
setFault(400,"Bad Request","400.99","Bad Request");
49+
break;
50+
51+
//401 Unauthorized
52+
case "ApiKeyNotApproved":
53+
case "CompanyStatusNotActive":
54+
case "DeveloperStatusNotActive":
55+
case "FailedToResolveAPIKey":
56+
case "InvalidApiKey":
57+
case "InvalidApiKeyForGivenResource":
58+
case "InvalidAPICallAsNoApiProductMatchFound":
59+
case "app_not_approved":
60+
case "FailedToResolveAccessToken":
61+
case "FailedToResolveToken":
62+
case "FailedToResolveAuthorizationCode":
63+
case "InvalidAccessToken":
3864
case "access_token_expired":
3965
case "invalid_access_token":
40-
case "InvalidAccessToken":
41-
setFault(
42-
401,
43-
"Unauthorized",
44-
"401.99",
45-
"Unauthorized - Token Invalid or Expired"
46-
);
66+
case "InvalidOperation":
67+
setFault(401,"Unauthorized","401.99","Unauthorized - Token Invalid or Expired");
68+
break;
69+
70+
//403 Forbidden
71+
case "InsufficientScope":
72+
setFault(403,"Forbidden","403.99","Forbidden");
4773
break;
74+
75+
//429 Too Many Requests
76+
case "SpikeArrestViolation":
77+
case "InvalidMessageWeight":
78+
case "ErrorLoadingProperties":
79+
case "FailedToResolveSpikeArrestRate":
80+
case "QuotaViolation":
81+
case "InvalidQuotaInterval":
82+
case "InvalidQuotaTimeUnit":
83+
case "FailedToResolveQuotaIntervalReference":
84+
case "FailedToResolveQuotaIntervalTimeUnitReference":
85+
setFault(429,"Too Many Requests","429.99","Too Many Requests");
86+
break;
87+
4888
case "ErrorResponseCode":
49-
switch (context.getVariable("response.status.code")) {
50-
case "400":
51-
setFault(400, "Bad Request", "400.99", "Invalid Request");
52-
break;
53-
case "404":
54-
setFault(404, "Resource Not Found", "404.99", "Resource Not Found");
55-
break;
56-
}
89+
setFault(context.getVariable("error.status.code"),context.getVariable("error.status.phrase"),context.getVariable("error.status.code")+".99",context.getVariable("error.status.phrase"));
90+
break;
91+
// switch (context.getVariable("response.status.code")) {
92+
// case "400":
93+
// setFault(400, "Bad Request", "400.99", "Invalid Request");
94+
// break;
95+
// case "404":
96+
// setFault(404, "Resource Not Found", "404.99", "Resource Not Found");
97+
// break;
98+
// }
5799
}
58100

59-
if (!context.getVariable("custom.error.code")) {
101+
if (context.getVariable("flow.error.code") == null || !context.getVariable("custom.error.code")) {
60102
setFault(500, "Internal Server Error", "500.99", "Internal Server Error");
61103
}

0 commit comments

Comments
 (0)