UNPKG

1.88 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 GraphClientError
10 */
11
12/**
13 * @class
14 * Create GraphClientError object to handle client-side errors
15 * encountered within the JavaScript Client SDK.
16 * Whereas GraphError Class should be used to handle errors in the response from the Graph API.
17 */
18
19export class GraphClientError extends Error {
20 /**
21 * @public
22 * A custom error. This property should set be when the error is not of instanceOf Error/GraphClientError.
23 * Example =
24 * const client = MicrosoftGraph.Client.init({
25 * defaultVersion: "v1.0",
26 * authProvider: (done) => { done({TokenError:"AccessToken cannot be null"}, "<ACCESS_TOKEN>");
27 * });
28 */
29 public customError?: any;
30
31 /**
32 * @public
33 * @static
34 * @async
35 * To set the GraphClientError object
36 * @param {any} error - The error returned encountered by the Graph JavaScript Client SDK while processing request
37 * @returns GraphClientError object set to the error passed
38 */
39 public static setGraphClientError(error: any): GraphClientError {
40 let graphClientError: GraphClientError;
41 if (error instanceof Error) {
42 graphClientError = error;
43 } else {
44 graphClientError = new GraphClientError();
45 graphClientError.customError = error;
46 }
47 return graphClientError;
48 }
49
50 /**
51 * @public
52 * @constructor
53 * Creates an instance of GraphClientError
54 * @param {string} message? - Error message
55 * @returns An instance of GraphClientError
56 */
57 public constructor(message?: string) {
58 super(message);
59 Object.setPrototypeOf(this, GraphClientError.prototype);
60 }
61}