Skip to content

Commit

Permalink
Pass through Chainport errors (#1798)
Browse files Browse the repository at this point in the history
  • Loading branch information
dguenther authored Dec 16, 2024
1 parent a1136b9 commit 90091c3
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/bridges/chainport.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
BadGatewayException,
Injectable,
NotFoundException,
UnprocessableEntityException,
} from '@nestjs/common';
import { AxiosError, AxiosResponse } from 'axios';
import Joi from 'joi';
Expand Down Expand Up @@ -163,6 +164,22 @@ export type ChainportPort =
port_in_ack: boolean | null;
};

export type ChainportError = {
error: {
code: string;
description: string;
};
status: string;
};

const chainportErrorSchema = Joi.object<ChainportError>({
error: Joi.object({
code: Joi.string().required(),
description: Joi.string().required(),
}).required(),
status: Joi.string().required(),
});

@Injectable()
export class ChainportService {
constructor(
Expand All @@ -185,6 +202,16 @@ export class ChainportService {
} - ${JSON.stringify(e.response?.data)}`,
e.stack ?? '',
);

const validationResult = chainportErrorSchema.validate(
e.response?.data,
);
if (!validationResult.error) {
throw new UnprocessableEntityException(
validationResult.value.error.description,
);
}

throw new BadGatewayException(e);
}),
),
Expand Down

0 comments on commit 90091c3

Please sign in to comment.