Skip to content

Commit

Permalink
fix(check-for-errors): throw an error for a response with a \`failure…
Browse files Browse the repository at this point in the history
…\` status

AFFECTS PACKAGES:
@esri/arcgis-rest-request
  • Loading branch information
Noah Mulfinger committed Aug 23, 2018
1 parent af61e3e commit 9ee1c0c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/arcgis-rest-request/src/utils/check-for-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ export function checkForErrors(
}

// error from a status check
if (response.status === "failed") {
if (response.status === "failed" || response.status === "failure") {
let message: string;
let code: string = "UNKNOWN_ERROR_CODE";

try {
message = JSON.parse(response.statusMessage).message;
code = JSON.parse(response.statusMessage).code;
} catch (e) {
message = response.statusMessage;
message = response.statusMessage || response.message;
}

throw new ArcGISRequestError(message, code, response, url, options);
Expand Down
6 changes: 6 additions & 0 deletions packages/arcgis-rest-request/test/mocks/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ export const BillingError: any = {
details: null as any
};

export const BillingErrorWithCode200: any = {
code: 200,
message: null,
status: "failure"
};

export const TaskErrorWithJSON: any = {
status: "failed",
statusMessage:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
ArcGISOnlineErrorNoMessageCode,
ArcGISOnlineErrorNoCode,
ArcGISServerTokenRequired,
ArcGISOnlineAuthError
ArcGISOnlineAuthError,
BillingErrorWithCode200
} from "./../mocks/errors";

describe("checkForErrors", () => {
Expand Down Expand Up @@ -60,6 +61,12 @@ describe("checkForErrors", () => {
}).toThrowError(ArcGISRequestError, "500: Error getting subscription info");
});

it("should throw an ArcGISRequestError for an error from the ArcGIS Online Billing Backend with a failure status", () => {
expect(() => {
checkForErrors(BillingErrorWithCode200);
}).toThrowError(ArcGISRequestError, null);
});

it("should throw an ArcGISRequestError for an error when checking long running tasks in ArcGIS REST API", () => {
expect(() => {
checkForErrors(TaskErrorWithJSON);
Expand Down

0 comments on commit 9ee1c0c

Please sign in to comment.