forked from microsoftgraph/msgraph-sdk-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GraphClientError.ts
61 lines (56 loc) · 1.83 KB
/
GraphClientError.ts
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
/**
* -------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
/**
* @module GraphClientError
*/
/**
* @class
* Create GraphClientError object to handle client-side errors
* encountered within the JavaScript Client SDK.
* Whereas GraphError Class should be used to handle errors in the response from the Graph API.
*/
export class GraphClientError extends Error {
/**
* @public
* A custom error. This property should set be when the error is not of instanceOf Error/GraphClientError.
* Example =
* const client = MicrosoftGraph.Client.init({
* defaultVersion: "v1.0",
* authProvider: (done) => { done({TokenError:"AccessToken cannot be null"}, "<ACCESS_TOKEN>");
* });
*/
public customError?: any;
/**
* @public
* @static
* @async
* To set the GraphClientError object
* @param {any} - The error returned encountered by the Graph JavaScript Client SDK while processing request
* @returns GraphClientError object set to the error passed
*/
public static setGraphClientError(error: any): GraphClientError {
let graphClientError: GraphClientError;
if (error instanceof Error) {
graphClientError = error;
} else {
graphClientError = new GraphClientError();
graphClientError.customError = error;
}
return graphClientError;
}
/**
* @public
* @constructor
* Creates an instance of GraphClientError
* @param {string} message? - Error message
* @returns An instance of GraphClientError
*/
public constructor(message?: string) {
super(message);
Object.setPrototypeOf(this, GraphClientError.prototype);
}
}