Skip to content

Commit ad4399b

Browse files
Make GraphError real Error (#335)
Co-authored-by: nikithauc <nikithauc@gmail.com>
1 parent f99d0ff commit ad4399b

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
lines changed

spec/core/GraphErrorHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ describe("GraphErrorHandler.ts", () => {
9797

9898
it("Should construct some default error", async () => {
9999
const gError = await GraphErrorHandler.getError();
100+
assert.equal(gError.message, "");
100101
assert.equal(gError.statusCode, -1);
101102
assert.equal(gError.code, null);
102-
assert.equal(gError.message, null);
103103
assert.equal(gError.body, null);
104104
assert.equal(gError.requestId, null);
105105
});

src/GraphError.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* Some fields are renamed ie, "request-id" => requestId so you can use dot notation
1818
*/
1919

20-
export class GraphError {
20+
export class GraphError extends Error {
2121
/**
2222
* @public
2323
* A member holding status code of the error
@@ -30,12 +30,6 @@ export class GraphError {
3030
*/
3131
public code: string | null;
3232

33-
/**
34-
* @public
35-
* A member holding error message
36-
*/
37-
public message: string | null;
38-
3933
/**
4034
* @public
4135
* A member holding request-id i.e identifier of the request
@@ -61,12 +55,13 @@ export class GraphError {
6155
* @param {number} [statusCode = -1] - The status code of the error
6256
* @returns An instance of GraphError
6357
*/
64-
public constructor(statusCode: number = -1) {
58+
public constructor(statusCode: number = -1, message?: string, baseError?: Error) {
59+
super(message || (baseError && baseError.message));
6560
this.statusCode = statusCode;
6661
this.code = null;
67-
this.message = null;
6862
this.requestId = null;
6963
this.date = new Date();
7064
this.body = null;
65+
this.stack = baseError ? baseError.stack : this.stack;
7166
}
7267
}

src/GraphErrorHandler.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@ export class GraphErrorHandler {
2727
* @returns The GraphError instance
2828
*/
2929
private static constructError(error: Error, statusCode?: number): GraphError {
30-
const gError = new GraphError(statusCode);
30+
const gError = new GraphError(statusCode, "", error);
3131
if (error.name !== undefined) {
3232
gError.code = error.name;
3333
}
3434
gError.body = error.toString();
35-
gError.message = error.message;
3635
gError.date = new Date();
3736
return gError;
3837
}
@@ -60,9 +59,8 @@ export class GraphErrorHandler {
6059
*/
6160
private static constructErrorFromResponse(error: any, statusCode: number): GraphError {
6261
error = error.error;
63-
const gError = new GraphError(statusCode);
62+
const gError = new GraphError(statusCode, error.message);
6463
gError.code = error.code;
65-
gError.message = error.message;
6664
if (error.innerError !== undefined) {
6765
gError.requestId = error.innerError["request-id"];
6866
gError.date = new Date(error.innerError.date);

0 commit comments

Comments
 (0)