Skip to content

Commit

Permalink
fix(ArcGISRequestError): replace null or empty messages and codes wit…
Browse files Browse the repository at this point in the history
…h UNKNOWN_ERROR and UNKNOWN_ERR

AFFECTS PACKAGES:
@esri/arcgis-rest-request
  • Loading branch information
Noah Mulfinger committed Aug 23, 2018
1 parent 9ee1c0c commit bcea1da
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
7 changes: 5 additions & 2 deletions packages/arcgis-rest-request/src/utils/ArcGISRequestError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@ export class ArcGISRequestError {
* @param options - The original options and parameters of the request
*/
constructor(
message = "UNKNOWN_ERROR",
code: string | number = "UNKNOWN_ERROR_CODE",
message?: string,
code?: string | number,
response?: any,
url?: string,
options?: IRequestOptions
) {
message = message || "UNKNOWN_ERROR";
code = code || "UNKNOWN_ERROR_CODE";

this.name = "ArcGISRequestError";
this.message =
code === "UNKNOWN_ERROR_CODE" ? message : `${code}: ${message}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,12 @@ describe("ArcGISRequestError", () => {
expect(error.originalMessage).toBe("UNKNOWN_ERROR");
expect(error.response).toEqual(undefined);
});

it("should still format with a null or empty string message or code", () => {
const error = new ArcGISRequestError(null, "");
expect(error.message).toBe("UNKNOWN_ERROR");
expect(error.code).toEqual("UNKNOWN_ERROR_CODE");
expect(error.originalMessage).toBe("UNKNOWN_ERROR");
expect(error.response).toEqual(undefined);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe("checkForErrors", () => {
it("should throw an ArcGISRequestError for an error from the ArcGIS Online Billing Backend with a failure status", () => {
expect(() => {
checkForErrors(BillingErrorWithCode200);
}).toThrowError(ArcGISRequestError, null);
}).toThrowError(ArcGISRequestError, "UNKNOWN_ERROR");
});

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

0 comments on commit bcea1da

Please sign in to comment.