@@ -40,13 +40,14 @@ export class GraphErrorHandler {
4040 * @param {number } [statusCode] - The status code of the response
4141 * @returns The GraphError instance
4242 */
43- private static constructError ( error : Error , statusCode ?: number ) : GraphError {
43+ private static constructError ( error : Error , statusCode ?: number , rawResponse ?: Response ) : GraphError {
4444 const gError = new GraphError ( statusCode , "" , error ) ;
4545 if ( error . name !== undefined ) {
4646 gError . code = error . name ;
4747 }
4848 gError . body = error . toString ( ) ;
4949 gError . date = new Date ( ) ;
50+ gError . headers = rawResponse ?. headers ;
5051 return gError ;
5152 }
5253
@@ -71,7 +72,7 @@ export class GraphErrorHandler {
7172 * }
7273 * }
7374 */
74- private static constructErrorFromResponse ( graphError : GraphAPIErrorResponse , statusCode : number ) : GraphError {
75+ private static constructErrorFromResponse ( graphError : GraphAPIErrorResponse , statusCode : number , rawResponse ?: Response ) : GraphError {
7576 const error = graphError . error ;
7677 const gError = new GraphError ( statusCode , error . message ) ;
7778 gError . code = error . code ;
@@ -81,6 +82,7 @@ export class GraphErrorHandler {
8182 }
8283
8384 gError . body = JSON . stringify ( error ) ;
85+ gError . headers = rawResponse ?. headers ;
8486
8587 return gError ;
8688 }
@@ -96,12 +98,12 @@ export class GraphErrorHandler {
9698 * @param {GraphRequestCallback } [callback] - The graph request callback function
9799 * @returns A promise that resolves to GraphError instance
98100 */
99- public static async getError ( error : any = null , statusCode = - 1 , callback ?: GraphRequestCallback ) : Promise < GraphError > {
101+ public static async getError ( error : any = null , statusCode = - 1 , callback ?: GraphRequestCallback , rawResponse ?: Response ) : Promise < GraphError > {
100102 let gError : GraphError ;
101103 if ( error && error . error ) {
102- gError = GraphErrorHandler . constructErrorFromResponse ( error , statusCode ) ;
104+ gError = GraphErrorHandler . constructErrorFromResponse ( error , statusCode , rawResponse ) ;
103105 } else if ( error instanceof Error ) {
104- gError = GraphErrorHandler . constructError ( error , statusCode ) ;
106+ gError = GraphErrorHandler . constructError ( error , statusCode , rawResponse ) ;
105107 } else {
106108 gError = new GraphError ( statusCode ) ;
107109 gError . body = error ; // if a custom error is passed which is not instance of Error object or a graph API response
0 commit comments