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
2 changes: 1 addition & 1 deletion spec/core/GraphErrorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add unit tests verifying if stack is set or defined as expected as per the new line added in this PR ->
this.stack = baseError ? baseError.stack : this.stack; ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably need an issue to track adding a stack assertion for each of the cases here.

Expand Down
13 changes: 4 additions & 9 deletions src/GraphError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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;
}
}
6 changes: 2 additions & 4 deletions src/GraphErrorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down