@@ -12,6 +12,15 @@ export class PermitApiError<T> extends Error {
1212 super ( message ) ;
1313 }
1414
15+ public get formattedAxiosError ( ) : any {
16+ return {
17+ code : this . originalError . code ,
18+ message : this . message ,
19+ error : this . originalError . response ?. data ,
20+ status : this . originalError . status ,
21+ } ;
22+ }
23+
1524 public get request ( ) : any {
1625 return this . originalError . request ;
1726 }
@@ -165,13 +174,14 @@ export abstract class BasePermitApi {
165174 protected handleApiError ( err : unknown ) : never {
166175 if ( axios . isAxiosError ( err ) ) {
167176 // this is an http response with an error status code
168- const message = `Got error status code: ${ err . response ?. status } , err: ${ JSON . stringify (
177+ const logMessage = `Got error status code: ${ err . response ?. status } , err: ${ JSON . stringify (
169178 err ?. response ?. data ,
170179 ) } `;
180+ const apiMessage = err . response ?. data . message ;
171181 // log this to the SDK logger
172- this . logger . error ( message ) ;
182+ this . logger . error ( logMessage ) ;
173183 // and throw a permit error exception
174- throw new PermitApiError ( message , err ) ;
184+ throw new PermitApiError ( apiMessage , err ) ;
175185 } else {
176186 // unexpected error, just throw
177187 throw err ;
0 commit comments