diff --git a/src/errors/__tests__/request_error.test.ts b/src/errors/__tests__/request_error.test.ts index e081f57b45..aaa10faffa 100644 --- a/src/errors/__tests__/request_error.test.ts +++ b/src/errors/__tests__/request_error.test.ts @@ -27,17 +27,19 @@ describe("errors - RequestError", () => { expect(requestError.xhr).toBe(xhr); expect(requestError.status).toBe(355); expect(requestError.type).toBe("ERROR_EVENT"); - expect(requestError.message).toBe("ERROR_EVENT"); + expect(requestError.message).toBe( + "An error prevented the request to be performed successfully" + ); xhr.abort(); }); it("should authorize no XHR", () => { - const requestError = new RequestError("foo", 355, "ERROR_EVENT"); + const requestError = new RequestError("foo", 355, "TIMEOUT"); expect(requestError).toBeInstanceOf(Error); expect(requestError.name).toBe("RequestError"); expect(requestError.url).toBe("foo"); expect(requestError.xhr).toBe(undefined); expect(requestError.status).toBe(355); - expect(requestError.type).toBe("ERROR_EVENT"); - expect(requestError.message).toBe("ERROR_EVENT"); + expect(requestError.type).toBe("TIMEOUT"); + expect(requestError.message).toBe("The request timeouted"); }); }); diff --git a/src/errors/request_error.ts b/src/errors/request_error.ts index ed4aafd5ba..35000be08f 100644 --- a/src/errors/request_error.ts +++ b/src/errors/request_error.ts @@ -56,6 +56,21 @@ export default class RequestError extends Error { } this.status = status; this.type = type; - this.message = type; + + switch (type) { + case "TIMEOUT": + this.message = "The request timeouted"; + break; + case "ERROR_EVENT": + this.message = "An error prevented the request to be performed successfully"; + break; + case "PARSE_ERROR": + this.message = "An error happened while formatting the response data"; + break; + case "ERROR_HTTP_CODE": + this.message = "An HTTP status code indicating failure was received: " + + String(this.status); + break; + } } }