diff --git a/packages/arcgis-rest-request/src/utils/check-for-errors.ts b/packages/arcgis-rest-request/src/utils/check-for-errors.ts index 5d48a6babb..6b5992f633 100644 --- a/packages/arcgis-rest-request/src/utils/check-for-errors.ts +++ b/packages/arcgis-rest-request/src/utils/check-for-errors.ts @@ -38,7 +38,7 @@ 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"; @@ -46,7 +46,7 @@ export function checkForErrors( 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); diff --git a/packages/arcgis-rest-request/test/mocks/errors.ts b/packages/arcgis-rest-request/test/mocks/errors.ts index 7c32620825..64aa99efc1 100644 --- a/packages/arcgis-rest-request/test/mocks/errors.ts +++ b/packages/arcgis-rest-request/test/mocks/errors.ts @@ -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: diff --git a/packages/arcgis-rest-request/test/utils/check-for-errors.test.ts b/packages/arcgis-rest-request/test/utils/check-for-errors.test.ts index edde8bf977..3fea299362 100644 --- a/packages/arcgis-rest-request/test/utils/check-for-errors.test.ts +++ b/packages/arcgis-rest-request/test/utils/check-for-errors.test.ts @@ -13,7 +13,8 @@ import { ArcGISOnlineErrorNoMessageCode, ArcGISOnlineErrorNoCode, ArcGISServerTokenRequired, - ArcGISOnlineAuthError + ArcGISOnlineAuthError, + BillingErrorWithCode200 } from "./../mocks/errors"; describe("checkForErrors", () => { @@ -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);