diff --git a/spec/core/GraphErrorHandler.ts b/spec/core/GraphErrorHandler.ts index f16ae3ebf..e16c05a4a 100644 --- a/spec/core/GraphErrorHandler.ts +++ b/spec/core/GraphErrorHandler.ts @@ -97,9 +97,9 @@ describe("GraphErrorHandler.ts", () => { it("Should construct some default error", async () => { const gError = await GraphErrorHandler.getError(); + assert.equal(gError.message, ""); assert.equal(gError.statusCode, -1); assert.equal(gError.code, null); - assert.equal(gError.message, null); assert.equal(gError.body, null); assert.equal(gError.requestId, null); }); diff --git a/src/GraphError.ts b/src/GraphError.ts index 08dc7bde2..d3433e879 100644 --- a/src/GraphError.ts +++ b/src/GraphError.ts @@ -17,7 +17,7 @@ * Some fields are renamed ie, "request-id" => requestId so you can use dot notation */ -export class GraphError { +export class GraphError extends Error { /** * @public * A member holding status code of the error @@ -30,12 +30,6 @@ export class GraphError { */ public code: string | null; - /** - * @public - * A member holding error message - */ - public message: string | null; - /** * @public * A member holding request-id i.e identifier of the request @@ -61,12 +55,13 @@ export class GraphError { * @param {number} [statusCode = -1] - The status code of the error * @returns An instance of GraphError */ - public constructor(statusCode: number = -1) { + public constructor(statusCode: number = -1, message?: string, baseError?: Error) { + super(message || (baseError && baseError.message)); this.statusCode = statusCode; this.code = null; - this.message = null; this.requestId = null; this.date = new Date(); this.body = null; + this.stack = baseError ? baseError.stack : this.stack; } } diff --git a/src/GraphErrorHandler.ts b/src/GraphErrorHandler.ts index e5506663d..310596968 100644 --- a/src/GraphErrorHandler.ts +++ b/src/GraphErrorHandler.ts @@ -27,12 +27,11 @@ export class GraphErrorHandler { * @returns The GraphError instance */ private static constructError(error: Error, statusCode?: number): GraphError { - const gError = new GraphError(statusCode); + const gError = new GraphError(statusCode, "", error); if (error.name !== undefined) { gError.code = error.name; } gError.body = error.toString(); - gError.message = error.message; gError.date = new Date(); return gError; } @@ -60,9 +59,8 @@ export class GraphErrorHandler { */ private static constructErrorFromResponse(error: any, statusCode: number): GraphError { error = error.error; - const gError = new GraphError(statusCode); + const gError = new GraphError(statusCode, error.message); gError.code = error.code; - gError.message = error.message; if (error.innerError !== undefined) { gError.requestId = error.innerError["request-id"]; gError.date = new Date(error.innerError.date);