Skip to content

Commit 90091c3

Browse files
authored
Pass through Chainport errors (#1798)
1 parent a1136b9 commit 90091c3

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/bridges/chainport.service.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
BadGatewayException,
77
Injectable,
88
NotFoundException,
9+
UnprocessableEntityException,
910
} from '@nestjs/common';
1011
import { AxiosError, AxiosResponse } from 'axios';
1112
import Joi from 'joi';
@@ -163,6 +164,22 @@ export type ChainportPort =
163164
port_in_ack: boolean | null;
164165
};
165166

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+
166183
@Injectable()
167184
export class ChainportService {
168185
constructor(
@@ -185,6 +202,16 @@ export class ChainportService {
185202
} - ${JSON.stringify(e.response?.data)}`,
186203
e.stack ?? '',
187204
);
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+
188215
throw new BadGatewayException(e);
189216
}),
190217
),

0 commit comments

Comments
 (0)