File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 6
6
BadGatewayException ,
7
7
Injectable ,
8
8
NotFoundException ,
9
+ UnprocessableEntityException ,
9
10
} from '@nestjs/common' ;
10
11
import { AxiosError , AxiosResponse } from 'axios' ;
11
12
import Joi from 'joi' ;
@@ -163,6 +164,22 @@ export type ChainportPort =
163
164
port_in_ack : boolean | null ;
164
165
} ;
165
166
167
+ export type ChainportError = {
168
+ error : {
169
+ code : string ;
170
+ description : string ;
171
+ } ;
172
+ status : string ;
173
+ } ;
174
+
175
+ const chainportErrorSchema = Joi . object < ChainportError > ( {
176
+ error : Joi . object ( {
177
+ code : Joi . string ( ) . required ( ) ,
178
+ description : Joi . string ( ) . required ( ) ,
179
+ } ) . required ( ) ,
180
+ status : Joi . string ( ) . required ( ) ,
181
+ } ) ;
182
+
166
183
@Injectable ( )
167
184
export class ChainportService {
168
185
constructor (
@@ -185,6 +202,16 @@ export class ChainportService {
185
202
} - ${ JSON . stringify ( e . response ?. data ) } `,
186
203
e . stack ?? '' ,
187
204
) ;
205
+
206
+ const validationResult = chainportErrorSchema . validate (
207
+ e . response ?. data ,
208
+ ) ;
209
+ if ( ! validationResult . error ) {
210
+ throw new UnprocessableEntityException (
211
+ validationResult . value . error . description ,
212
+ ) ;
213
+ }
214
+
188
215
throw new BadGatewayException ( e ) ;
189
216
} ) ,
190
217
) ,
You can’t perform that action at this time.
0 commit comments