Skip to content

Commit c7deec2

Browse files
authored
Setting GraphError prototype explicity. Version 2.1.1 (#347)
1 parent b05fc9c commit c7deec2

File tree

5 files changed

+12
-3
lines changed

5 files changed

+12
-3
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@microsoft/microsoft-graph-client",
3-
"version": "2.1.0",
3+
"version": "2.1.1",
44
"description": "Microsoft Graph Client Library",
55
"license": "MIT",
66
"main": "lib/src/index.js",

spec/core/GraphErrorHandler.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import { assert } from "chai";
99

10+
import { GraphError } from "../../src";
1011
import { GraphErrorHandler } from "../../src/GraphErrorHandler";
1112

1213
describe("GraphErrorHandler.ts", () => {
@@ -41,6 +42,7 @@ describe("GraphErrorHandler.ts", () => {
4142

4243
it("Should construct error for error response without innerError property", () => {
4344
const gError = GraphErrorHandler["constructErrorFromResponse"](error, statusCode);
45+
assert.isTrue(gError instanceof GraphError);
4446
assert.equal(gError.statusCode, statusCode);
4547
assert.equal(gError.requestId, null);
4648
});
@@ -50,6 +52,7 @@ describe("GraphErrorHandler.ts", () => {
5052
"request-id": "some random id",
5153
};
5254
const gError = GraphErrorHandler["constructErrorFromResponse"](error, statusCode);
55+
assert.isTrue(gError instanceof GraphError);
5356
assert.equal(gError.statusCode, statusCode);
5457
assert.equal(gError.requestId, "some random id");
5558
});
@@ -62,6 +65,7 @@ describe("GraphErrorHandler.ts", () => {
6265
date,
6366
};
6467
const gError = GraphErrorHandler["constructErrorFromResponse"](error, statusCode);
68+
assert.isTrue(gError instanceof GraphError);
6569
assert.equal(gError.statusCode, statusCode);
6670
assert.equal(gError.requestId, "some random id");
6771
assert.equal(gError.date.toUTCString(), date.toUTCString());
@@ -81,6 +85,7 @@ describe("GraphErrorHandler.ts", () => {
8185
},
8286
};
8387
const gError = await GraphErrorHandler.getError(errorResponse);
88+
assert.isTrue(gError instanceof GraphError);
8489
assert.equal(gError.requestId, "some random id");
8590
assert.equal(gError.code, "500");
8691
assert.equal(gError.message, "Internal Server Error");
@@ -90,13 +95,15 @@ describe("GraphErrorHandler.ts", () => {
9095
const error = new Error("Some Error");
9196
error.name = "InvalidError";
9297
const gError = await GraphErrorHandler.getError(error);
98+
assert.isTrue(gError instanceof GraphError);
9399
assert.equal(gError.requestId, null);
94100
assert.equal(gError.message, "Some Error");
95101
assert.equal(gError.code, "InvalidError");
96102
});
97103

98104
it("Should construct some default error", async () => {
99105
const gError = await GraphErrorHandler.getError();
106+
assert.isTrue(gError instanceof GraphError);
100107
assert.equal(gError.message, "");
101108
assert.equal(gError.statusCode, -1);
102109
assert.equal(gError.code, null);

src/GraphError.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ export class GraphError extends Error {
5757
*/
5858
public constructor(statusCode: number = -1, message?: string, baseError?: Error) {
5959
super(message || (baseError && baseError.message));
60+
// https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work
61+
Object.setPrototypeOf(this, GraphError.prototype);
6062
this.statusCode = statusCode;
6163
this.code = null;
6264
this.requestId = null;

src/Version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
* @module Version
1313
*/
1414

15-
export const PACKAGE_VERSION = "2.1.0";
15+
export const PACKAGE_VERSION = "2.1.1";

0 commit comments

Comments
 (0)