@@ -7,11 +7,26 @@ import { BASE_PATH } from '../openapi/base';
77
88import { API_ACCESS_LEVELS , ApiContextLevel , ApiKeyLevel , PermitContextError } from './context' ;
99
10+ interface FormattedAxiosError {
11+ code : string | undefined ;
12+ message : string ;
13+ error : any ;
14+ status : number | undefined ;
15+ }
1016export class PermitApiError < T > extends Error {
1117 constructor ( message : string , public originalError : AxiosError < T > ) {
1218 super ( message ) ;
1319 }
1420
21+ public get formattedAxiosError ( ) : FormattedAxiosError {
22+ return {
23+ code : this . originalError . code ,
24+ message : this . message ,
25+ error : this . originalError . response ?. data ,
26+ status : this . originalError . status ,
27+ } ;
28+ }
29+
1530 public get request ( ) : any {
1631 return this . originalError . request ;
1732 }
@@ -165,11 +180,14 @@ export abstract class BasePermitApi {
165180 protected handleApiError ( err : unknown ) : never {
166181 if ( axios . isAxiosError ( err ) ) {
167182 // this is an http response with an error status code
168- const message = `Got error status code: ${ err . response ?. status } ` ;
183+ const logMessage = `Got error status code: ${ err . response ?. status } , err: ${ JSON . stringify (
184+ err ?. response ?. data ,
185+ ) } `;
186+ const apiMessage = err . response ?. data . message ;
169187 // log this to the SDK logger
170- this . logger . error ( ` ${ message } , err: ${ JSON . stringify ( err ?. response ?. data ) } ` ) ;
188+ this . logger . error ( logMessage ) ;
171189 // and throw a permit error exception
172- throw new PermitApiError ( message , err ) ;
190+ throw new PermitApiError ( apiMessage , err ) ;
173191 } else {
174192 // unexpected error, just throw
175193 throw err ;
0 commit comments