Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions spec/core/GraphErrorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
12 changes: 0 additions & 12 deletions spec/core/GraphResponseHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
});
});
23 changes: 1 addition & 22 deletions src/GraphErrorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<GraphError> {
const gError = new GraphError(statusCode);
try {
gError.body = await error.text();
} catch (error) {
// tslint:disable-line: no-empty
}
return gError;
}

/**
* @private
* @static
Expand Down Expand Up @@ -106,9 +87,7 @@ export class GraphErrorHandler {
*/
public static async getError(error: any = null, statusCode: number = -1, callback?: GraphRequestCallback): Promise<GraphError> {
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);
Expand Down
2 changes: 1 addition & 1 deletion src/GraphResponseHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export class GraphResponseHandler {
}
}
} catch (error) {
throw rawResponse.ok ? error : rawResponse;
throw error;
}
}
}