File tree Expand file tree Collapse file tree 3 files changed +7
-14
lines changed Expand file tree Collapse file tree 3 files changed +7
-14
lines changed Original file line number Diff line number Diff line change @@ -97,9 +97,9 @@ describe("GraphErrorHandler.ts", () => {
9797
9898 it ( "Should construct some default error" , async ( ) => {
9999 const gError = await GraphErrorHandler . getError ( ) ;
100+ assert . equal ( gError . message , "" ) ;
100101 assert . equal ( gError . statusCode , - 1 ) ;
101102 assert . equal ( gError . code , null ) ;
102- assert . equal ( gError . message , null ) ;
103103 assert . equal ( gError . body , null ) ;
104104 assert . equal ( gError . requestId , null ) ;
105105 } ) ;
Original file line number Diff line number Diff line change 1717 * Some fields are renamed ie, "request-id" => requestId so you can use dot notation
1818 */
1919
20- export class GraphError {
20+ export class GraphError extends Error {
2121 /**
2222 * @public
2323 * A member holding status code of the error
@@ -30,12 +30,6 @@ export class GraphError {
3030 */
3131 public code : string | null ;
3232
33- /**
34- * @public
35- * A member holding error message
36- */
37- public message : string | null ;
38-
3933 /**
4034 * @public
4135 * A member holding request-id i.e identifier of the request
@@ -61,12 +55,13 @@ export class GraphError {
6155 * @param {number } [statusCode = -1] - The status code of the error
6256 * @returns An instance of GraphError
6357 */
64- public constructor ( statusCode : number = - 1 ) {
58+ public constructor ( statusCode : number = - 1 , message ?: string , baseError ?: Error ) {
59+ super ( message || ( baseError && baseError . message ) ) ;
6560 this . statusCode = statusCode ;
6661 this . code = null ;
67- this . message = null ;
6862 this . requestId = null ;
6963 this . date = new Date ( ) ;
7064 this . body = null ;
65+ this . stack = baseError ? baseError . stack : this . stack ;
7166 }
7267}
Original file line number Diff line number Diff line change @@ -27,12 +27,11 @@ export class GraphErrorHandler {
2727 * @returns The GraphError instance
2828 */
2929 private static constructError ( error : Error , statusCode ?: number ) : GraphError {
30- const gError = new GraphError ( statusCode ) ;
30+ const gError = new GraphError ( statusCode , "" , error ) ;
3131 if ( error . name !== undefined ) {
3232 gError . code = error . name ;
3333 }
3434 gError . body = error . toString ( ) ;
35- gError . message = error . message ;
3635 gError . date = new Date ( ) ;
3736 return gError ;
3837 }
@@ -60,9 +59,8 @@ export class GraphErrorHandler {
6059 */
6160 private static constructErrorFromResponse ( error : any , statusCode : number ) : GraphError {
6261 error = error . error ;
63- const gError = new GraphError ( statusCode ) ;
62+ const gError = new GraphError ( statusCode , error . message ) ;
6463 gError . code = error . code ;
65- gError . message = error . message ;
6664 if ( error . innerError !== undefined ) {
6765 gError . requestId = error . innerError [ "request-id" ] ;
6866 gError . date = new Date ( error . innerError . date ) ;
You can’t perform that action at this time.
0 commit comments