@@ -28,7 +28,7 @@ export class ApplicationException<CodeT> extends Error {
2828export interface ErrorEntry < CodeT > {
2929 code : CodeT ;
3030 condition ?: ( error : unknown ) => boolean ;
31- getMessage : ( error : unknown , t : TFunction ) => string ;
31+ getMessage : ( t : TFunction , error : unknown ) => string ;
3232}
3333
3434export interface ErrorHandlerOptions < CodeT extends string > {
@@ -98,7 +98,14 @@ export class ErrorHandler<CodeT extends string> {
9898 const unknownError : ErrorEntry < ICodeT > = {
9999 code : "UNKNOWN_ERROR" ,
100100 condition : ( ) => true ,
101- getMessage : ( ) => this . t ( "openapi.sharedErrors.unknownError" ) ,
101+ getMessage : ( e ) => {
102+ if ( axios . isAxiosError ( e ) && e . response ?. data ?. code ) {
103+ return this . t ( "openapi.sharedErrors.unknownErrorWithCode" , {
104+ code : e . response . data . code ,
105+ } ) ;
106+ }
107+ return this . t ( "openapi.sharedErrors.unknownError" ) ;
108+ } ,
102109 } ;
103110
104111 // general errors have the lowest priority
@@ -121,7 +128,7 @@ export class ErrorHandler<CodeT extends string> {
121128 const errorEntry = this . entries . find ( ( entry ) => this . matchesEntry ( error , entry , code ) ) ! ;
122129
123130 const serverMessage = RestUtils . extractServerErrorMessage ( error ) ;
124- const exception = new ApplicationException ( errorEntry . getMessage ( error , this . t ) , errorEntry . code , serverMessage ) ;
131+ const exception = new ApplicationException ( errorEntry . getMessage ( this . t , error ) , errorEntry . code , serverMessage ) ;
125132
126133 this . onRethrowError ?.( error , exception ) ;
127134
0 commit comments