UNPKG

1.96 kBPlain TextView Raw
1/**
2 * -------------------------------------------------------------------------------------------
3 * Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
4 * See License in the project root for license information.
5 * -------------------------------------------------------------------------------------------
6 */
7
8/**
9 * @module GraphError
10 */
11
12/**
13 * @class
14 * Class for GraphError
15 * @NOTE: This is NOT what is returned from the Graph
16 * GraphError is created from parsing JSON errors returned from the graph
17 * Some fields are renamed ie, "request-id" => requestId so you can use dot notation
18 */
19
20export class GraphError extends Error {
21 /**
22 * @public
23 * A member holding status code of the error
24 */
25 public statusCode: number;
26
27 /**
28 * @public
29 * A member holding code i.e name of the error
30 */
31 public code: string | null;
32
33 /**
34 * @public
35 * A member holding request-id i.e identifier of the request
36 */
37 public requestId: string | null;
38
39 /**
40 * @public
41 * A member holding processed date and time of the request
42 */
43 public date: Date;
44
45 /**
46 * @public
47 * A member holding original error response by the graph service
48 */
49 public body: any;
50
51 /**
52 * @public
53 * @constructor
54 * Creates an instance of GraphError
55 * @param {number} [statusCode = -1] - The status code of the error
56 * @returns An instance of GraphError
57 */
58 public constructor(statusCode = -1, message?: string, baseError?: Error) {
59 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);
62 this.statusCode = statusCode;
63 this.code = null;
64 this.requestId = null;
65 this.date = new Date();
66 this.body = null;
67 this.stack = baseError ? baseError.stack : this.stack;
68 }
69}