diff --git a/spec/core/GraphErrorHandler.ts b/spec/core/GraphErrorHandler.ts index 95f635c30..f16ae3ebf 100644 --- a/spec/core/GraphErrorHandler.ts +++ b/spec/core/GraphErrorHandler.ts @@ -30,29 +30,6 @@ describe("GraphErrorHandler.ts", () => { }); }); - describe("constructErrorFromRawResponse", async () => { - it("Should parse error from raw response", async () => { - const body = "unauthorized"; - const statusCode = 401; - const errorResponse = new Response(body, { - status: statusCode, - }); - const gError = await GraphErrorHandler["constructErrorFromRawResponse"](errorResponse, statusCode); - assert.equal(gError.statusCode, statusCode); - assert.equal(gError.body, body); - }); - - it("Should parse error without body", async () => { - const statusCode = 401; - const errorResponse = new Response(undefined, { - status: statusCode, - }); - const gError = await GraphErrorHandler["constructErrorFromRawResponse"](errorResponse, statusCode); - assert.equal(gError.statusCode, statusCode); - assert.isNull(gError.body); - }); - }); - describe("constructErrorFromResponse", () => { const statusCode = 400; const error: any = { diff --git a/spec/core/GraphResponseHandler.ts b/spec/core/GraphResponseHandler.ts index c3da32e99..e5c1a1052 100644 --- a/spec/core/GraphResponseHandler.ts +++ b/spec/core/GraphResponseHandler.ts @@ -158,17 +158,5 @@ describe("GraphResponseHandler.ts", () => { const responseValue = await GraphResponseHandler.getResponse(response, ResponseType.TEXT); assert.isDefined(responseValue); }); - - it("Should parse from raw response for NOT OK response", async () => { - try { - const response = new Response("NOT OK", status500); - const responseValue = await GraphResponseHandler.getResponse(response, ResponseType.TEXT); - throw new Error("Something wrong with validating OK response"); - } catch (error) { - assert.isDefined(error); - assert.isTrue(error instanceof Response); - assert.equal(error.status, 500); - } - }); }); }); diff --git a/src/GraphErrorHandler.ts b/src/GraphErrorHandler.ts index 286a52283..e60374110 100644 --- a/src/GraphErrorHandler.ts +++ b/src/GraphErrorHandler.ts @@ -37,25 +37,6 @@ export class GraphErrorHandler { return gError; } - /** - * @private - * @static - * @async - * To construct error from the raw response - * @param {Response} error - The error response - * @param {number} statusCode - The status code of the response - * @returns A promise that resolves to GraphError instance - */ - private static async constructErrorFromRawResponse(error: Response, statusCode: number): Promise { - const gError = new GraphError(statusCode); - try { - gError.body = await error.text(); - } catch (error) { - // tslint:disable-line: no-empty - } - return gError; - } - /** * @private * @static @@ -106,9 +87,7 @@ export class GraphErrorHandler { */ public static async getError(error: any = null, statusCode: number = -1, callback?: GraphRequestCallback): Promise { let gError: GraphError; - if (error && (error.constructor.name === "Response" || error.constructor.name === "Body")) { - gError = await GraphErrorHandler.constructErrorFromRawResponse(error, statusCode); - } else if (error && error.error) { + if (error && error.error) { gError = GraphErrorHandler.constructErrorFromResponse(error, statusCode); } else if (error && error.constructor.name === "Error") { gError = GraphErrorHandler.constructError(error, statusCode); diff --git a/src/GraphResponseHandler.ts b/src/GraphResponseHandler.ts index 6b6d1962f..0a0bfbd3f 100644 --- a/src/GraphResponseHandler.ts +++ b/src/GraphResponseHandler.ts @@ -188,7 +188,7 @@ export class GraphResponseHandler { } } } catch (error) { - throw rawResponse.ok ? error : rawResponse; + throw error; } } }