UNPKG

2.03 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 public headers?: Headers;
46
47 /**
48 * @public
49 * A member holding original error response by the graph service
50 */
51 public body: any;
52
53 /**
54 * @public
55 * @constructor
56 * Creates an instance of GraphError
57 * @param {number} [statusCode = -1] - The status code of the error
58 * @param {string} [message] - The message of the error
59 * @param {Error} [baseError] - The base error
60 * @returns An instance of GraphError
61 */
62 public constructor(statusCode = -1, message?: string, baseError?: Error) {
63 super(message || (baseError && baseError.message));
64 // https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work
65 Object.setPrototypeOf(this, GraphError.prototype);
66 this.statusCode = statusCode;
67 this.code = null;
68 this.requestId = null;
69 this.date = new Date();
70 this.body = null;
71 this.stack = baseError ? baseError.stack : this.stack;
72 }
73}