mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
Merge branch 'fix/stricter-is-http-error-check' of https://github.com/glebbash/nest into fix/stricter-is-http-error-check
This commit is contained in:
@@ -88,6 +88,38 @@ describe('ExceptionsHandler', () => {
|
||||
}),
|
||||
).to.be.true;
|
||||
});
|
||||
it('should treat fastify errors as http errors', () => {
|
||||
const fastifyError = fastifyErrors.createError(
|
||||
'FST_ERR_CTP_EMPTY_JSON_BODY',
|
||||
"Body cannot be empty when content-type is set to 'application/json'",
|
||||
400,
|
||||
)();
|
||||
handler.next(fastifyError, new ExecutionContextHost([0, response]));
|
||||
|
||||
expect(statusStub.calledWith(400)).to.be.true;
|
||||
expect(
|
||||
jsonStub.calledWith({
|
||||
statusCode: 400,
|
||||
message:
|
||||
"Body cannot be empty when content-type is set to 'application/json'",
|
||||
}),
|
||||
).to.be.true;
|
||||
});
|
||||
it('should not treat errors from external API calls as errors from "http-errors" library', () => {
|
||||
const apiCallError = Object.assign(
|
||||
new Error('Some external API call failed'),
|
||||
{ status: 400 },
|
||||
);
|
||||
handler.next(apiCallError, new ExecutionContextHost([0, response]));
|
||||
|
||||
expect(statusStub.calledWith(500)).to.be.true;
|
||||
expect(
|
||||
jsonStub.calledWith({
|
||||
statusCode: 500,
|
||||
message: 'Internal server error',
|
||||
}),
|
||||
).to.be.true;
|
||||
});
|
||||
describe('when exception is instantiated by "http-errors" library', () => {
|
||||
it('should send expected response status code and message', () => {
|
||||
const error = new createHttpError.NotFound('User does not exist');
|
||||
|
||||
Reference in New Issue
Block a user