-
Notifications
You must be signed in to change notification settings - Fork 234
Expand file tree
/
Copy pathGraphError.ts
More file actions
73 lines (64 loc) · 1.98 KB
/
GraphError.ts
File metadata and controls
73 lines (64 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* -------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
/**
* @module GraphError
*/
/**
* @class
* Class for GraphError
* @NOTE: This is NOT what is returned from the Graph
* GraphError is created from parsing JSON errors returned from the graph
* Some fields are renamed ie, "request-id" => requestId so you can use dot notation
*/
export class GraphError extends Error {
/**
* @public
* A member holding status code of the error
*/
public statusCode: number;
/**
* @public
* A member holding code i.e name of the error
*/
public code: string | null;
/**
* @public
* A member holding request-id i.e identifier of the request
*/
public requestId: string | null;
/**
* @public
* A member holding processed date and time of the request
*/
public date: Date;
public headers?: Headers;
/**
* @public
* A member holding original error response by the graph service
*/
public body: any;
/**
* @public
* @constructor
* Creates an instance of GraphError
* @param {number} [statusCode = -1] - The status code of the error
* @param {string} [message] - The message of the error
* @param {Error} [baseError] - The base error
* @returns An instance of GraphError
*/
public constructor(statusCode = -1, message?: string, baseError?: Error) {
super(message || (baseError && baseError.message));
// https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work
Object.setPrototypeOf(this, GraphError.prototype);
this.statusCode = statusCode;
this.code = null;
this.requestId = null;
this.date = new Date();
this.body = null;
this.stack = baseError ? baseError.stack : this.stack;
}
}