Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/common/exceptions/bad-gateway.exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ export class BadGatewayException extends HttpException {
objectOrError?: any,
descriptionOrOptions: string | HttpExceptionOptions = 'Bad Gateway',
) {
const { description, httpExceptionOptions } =
const { description = 'Bad Gateway', httpExceptionOptions } =
HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);

super(
HttpException.createBody(
objectOrError,
description!,
description,
HttpStatus.BAD_GATEWAY,
),
HttpStatus.BAD_GATEWAY,
Expand Down
4 changes: 2 additions & 2 deletions packages/common/exceptions/bad-request.exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ export class BadRequestException extends HttpException {
objectOrError?: any,
descriptionOrOptions: string | HttpExceptionOptions = 'Bad Request',
) {
const { description, httpExceptionOptions } =
const { description = 'Bad Request', httpExceptionOptions } =
HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);

super(
HttpException.createBody(
objectOrError,
description!,
description,
HttpStatus.BAD_REQUEST,
),
HttpStatus.BAD_REQUEST,
Expand Down
4 changes: 2 additions & 2 deletions packages/common/exceptions/conflict.exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ export class ConflictException extends HttpException {
objectOrError?: any,
descriptionOrOptions: string | HttpExceptionOptions = 'Conflict',
) {
const { description, httpExceptionOptions } =
const { description = 'Conflict', httpExceptionOptions } =
HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);

super(
HttpException.createBody(
objectOrError,
description!,
description,
HttpStatus.CONFLICT,
),
HttpStatus.CONFLICT,
Expand Down
4 changes: 2 additions & 2 deletions packages/common/exceptions/forbidden.exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ export class ForbiddenException extends HttpException {
objectOrError?: any,
descriptionOrOptions: string | HttpExceptionOptions = 'Forbidden',
) {
const { description, httpExceptionOptions } =
const { description = 'Forbidden', httpExceptionOptions } =
HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);

super(
HttpException.createBody(
objectOrError,
description!,
description,
HttpStatus.FORBIDDEN,
),
HttpStatus.FORBIDDEN,
Expand Down
4 changes: 2 additions & 2 deletions packages/common/exceptions/gateway-timeout.exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ export class GatewayTimeoutException extends HttpException {
objectOrError?: any,
descriptionOrOptions: string | HttpExceptionOptions = 'Gateway Timeout',
) {
const { description, httpExceptionOptions } =
const { description = 'Gateway Timeout', httpExceptionOptions } =
HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);

super(
HttpException.createBody(
objectOrError,
description!,
description,
HttpStatus.GATEWAY_TIMEOUT,
),
HttpStatus.GATEWAY_TIMEOUT,
Expand Down
4 changes: 2 additions & 2 deletions packages/common/exceptions/gone.exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ export class GoneException extends HttpException {
objectOrError?: any,
descriptionOrOptions: string | HttpExceptionOptions = 'Gone',
) {
const { description, httpExceptionOptions } =
const { description = 'Gone', httpExceptionOptions } =
HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);

super(
HttpException.createBody(objectOrError, description!, HttpStatus.GONE),
HttpException.createBody(objectOrError, description, HttpStatus.GONE),
HttpStatus.GONE,
httpExceptionOptions,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ export class HttpVersionNotSupportedException extends HttpException {
| string
| HttpExceptionOptions = 'HTTP Version Not Supported',
) {
const { description, httpExceptionOptions } =
const { description = 'HTTP Version Not Supported', httpExceptionOptions } =
HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);

super(
HttpException.createBody(
objectOrError,
description!,
description,
HttpStatus.HTTP_VERSION_NOT_SUPPORTED,
),
HttpStatus.HTTP_VERSION_NOT_SUPPORTED,
Expand Down
4 changes: 2 additions & 2 deletions packages/common/exceptions/im-a-teapot.exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ export class ImATeapotException extends HttpException {
objectOrError?: any,
descriptionOrOptions: string | HttpExceptionOptions = `I'm a teapot`,
) {
const { description, httpExceptionOptions } =
const { description = `I'm a teapot`, httpExceptionOptions } =
HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);

super(
HttpException.createBody(
objectOrError,
description!,
description,
HttpStatus.I_AM_A_TEAPOT,
),
HttpStatus.I_AM_A_TEAPOT,
Expand Down
4 changes: 2 additions & 2 deletions packages/common/exceptions/internal-server-error.exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ export class InternalServerErrorException extends HttpException {
| string
| HttpExceptionOptions = 'Internal Server Error',
) {
const { description, httpExceptionOptions } =
const { description = 'Internal Server Error', httpExceptionOptions } =
HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);

super(
HttpException.createBody(
objectOrError,
description!,
description,
HttpStatus.INTERNAL_SERVER_ERROR,
),
HttpStatus.INTERNAL_SERVER_ERROR,
Expand Down
4 changes: 2 additions & 2 deletions packages/common/exceptions/method-not-allowed.exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ export class MethodNotAllowedException extends HttpException {
objectOrError?: any,
descriptionOrOptions: string | HttpExceptionOptions = 'Method Not Allowed',
) {
const { description, httpExceptionOptions } =
const { description = 'Method Not Allowed', httpExceptionOptions } =
HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);

super(
HttpException.createBody(
objectOrError,
description!,
description,
HttpStatus.METHOD_NOT_ALLOWED,
),
HttpStatus.METHOD_NOT_ALLOWED,
Expand Down
4 changes: 2 additions & 2 deletions packages/common/exceptions/misdirected.exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ export class MisdirectedException extends HttpException {
objectOrError?: any,
descriptionOrOptions: string | HttpExceptionOptions = 'Misdirected',
) {
const { description, httpExceptionOptions } =
const { description = 'Misdirected', httpExceptionOptions } =
HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);

super(
HttpException.createBody(
objectOrError,
description!,
description,
HttpStatus.MISDIRECTED,
),
HttpStatus.MISDIRECTED,
Expand Down
4 changes: 2 additions & 2 deletions packages/common/exceptions/not-acceptable.exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ export class NotAcceptableException extends HttpException {
objectOrError?: any,
descriptionOrOptions: string | HttpExceptionOptions = 'Not Acceptable',
) {
const { description, httpExceptionOptions } =
const { description = 'Not Acceptable', httpExceptionOptions } =
HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);

super(
HttpException.createBody(
objectOrError,
description!,
description,
HttpStatus.NOT_ACCEPTABLE,
),
HttpStatus.NOT_ACCEPTABLE,
Expand Down
4 changes: 2 additions & 2 deletions packages/common/exceptions/not-found.exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ export class NotFoundException extends HttpException {
objectOrError?: any,
descriptionOrOptions: string | HttpExceptionOptions = 'Not Found',
) {
const { description, httpExceptionOptions } =
const { description = 'Not Found', httpExceptionOptions } =
HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);

super(
HttpException.createBody(
objectOrError,
description!,
description,
HttpStatus.NOT_FOUND,
),
HttpStatus.NOT_FOUND,
Expand Down
4 changes: 2 additions & 2 deletions packages/common/exceptions/not-implemented.exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ export class NotImplementedException extends HttpException {
objectOrError?: any,
descriptionOrOptions: string | HttpExceptionOptions = 'Not Implemented',
) {
const { description, httpExceptionOptions } =
const { description = 'Not Implemented', httpExceptionOptions } =
HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);

super(
HttpException.createBody(
objectOrError,
description!,
description,
HttpStatus.NOT_IMPLEMENTED,
),
HttpStatus.NOT_IMPLEMENTED,
Expand Down
4 changes: 2 additions & 2 deletions packages/common/exceptions/payload-too-large.exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ export class PayloadTooLargeException extends HttpException {
objectOrError?: any,
descriptionOrOptions: string | HttpExceptionOptions = 'Payload Too Large',
) {
const { description, httpExceptionOptions } =
const { description = 'Payload Too Large', httpExceptionOptions } =
HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);

super(
HttpException.createBody(
objectOrError,
description!,
description,
HttpStatus.PAYLOAD_TOO_LARGE,
),
HttpStatus.PAYLOAD_TOO_LARGE,
Expand Down
4 changes: 2 additions & 2 deletions packages/common/exceptions/precondition-failed.exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ export class PreconditionFailedException extends HttpException {
objectOrError?: any,
descriptionOrOptions: string | HttpExceptionOptions = 'Precondition Failed',
) {
const { description, httpExceptionOptions } =
const { description = 'Precondition Failed', httpExceptionOptions } =
HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);

super(
HttpException.createBody(
objectOrError,
description!,
description,
HttpStatus.PRECONDITION_FAILED,
),
HttpStatus.PRECONDITION_FAILED,
Expand Down
4 changes: 2 additions & 2 deletions packages/common/exceptions/request-timeout.exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ export class RequestTimeoutException extends HttpException {
objectOrError?: any,
descriptionOrOptions: string | HttpExceptionOptions = 'Request Timeout',
) {
const { description, httpExceptionOptions } =
const { description = 'Request Timeout', httpExceptionOptions } =
HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);

super(
HttpException.createBody(
objectOrError,
description!,
description,
HttpStatus.REQUEST_TIMEOUT,
),
HttpStatus.REQUEST_TIMEOUT,
Expand Down
4 changes: 2 additions & 2 deletions packages/common/exceptions/service-unavailable.exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ export class ServiceUnavailableException extends HttpException {
objectOrError?: any,
descriptionOrOptions: string | HttpExceptionOptions = 'Service Unavailable',
) {
const { description, httpExceptionOptions } =
const { description = 'Service Unavailable', httpExceptionOptions } =
HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);

super(
HttpException.createBody(
objectOrError,
description!,
description,
HttpStatus.SERVICE_UNAVAILABLE,
),
HttpStatus.SERVICE_UNAVAILABLE,
Expand Down
4 changes: 2 additions & 2 deletions packages/common/exceptions/unauthorized.exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ export class UnauthorizedException extends HttpException {
objectOrError?: any,
descriptionOrOptions: string | HttpExceptionOptions = 'Unauthorized',
) {
const { description, httpExceptionOptions } =
const { description = 'Unauthorized', httpExceptionOptions } =
HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);

super(
HttpException.createBody(
objectOrError,
description!,
description,
HttpStatus.UNAUTHORIZED,
),
HttpStatus.UNAUTHORIZED,
Expand Down
4 changes: 2 additions & 2 deletions packages/common/exceptions/unprocessable-entity.exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ export class UnprocessableEntityException extends HttpException {
| string
| HttpExceptionOptions = 'Unprocessable Entity',
) {
const { description, httpExceptionOptions } =
const { description = 'Unprocessable Entity', httpExceptionOptions } =
HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);

super(
HttpException.createBody(
objectOrError,
description!,
description,
HttpStatus.UNPROCESSABLE_ENTITY,
),
HttpStatus.UNPROCESSABLE_ENTITY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ export class UnsupportedMediaTypeException extends HttpException {
| string
| HttpExceptionOptions = 'Unsupported Media Type',
) {
const { description, httpExceptionOptions } =
const { description = 'Unsupported Media Type', httpExceptionOptions } =
HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);

super(
HttpException.createBody(
objectOrError,
description!,
description,
HttpStatus.UNSUPPORTED_MEDIA_TYPE,
),
HttpStatus.UNSUPPORTED_MEDIA_TYPE,
Expand Down
44 changes: 44 additions & 0 deletions packages/common/test/exceptions/http.exception.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,5 +267,49 @@ describe('HttpException', () => {
expect(cause).to.be.eql(errorCause);
});
});

it('should preserve default description when using options with cause', () => {
const builtInExceptionsWithDefaults: [Type<HttpException>, string][] = [
[BadGatewayException, 'Bad Gateway'],
[BadRequestException, 'Bad Request'],
[ConflictException, 'Conflict'],
[ForbiddenException, 'Forbidden'],
[GatewayTimeoutException, 'Gateway Timeout'],
[GoneException, 'Gone'],
[HttpVersionNotSupportedException, 'HTTP Version Not Supported'],
[ImATeapotException, `I'm a teapot`],
[InternalServerErrorException, 'Internal Server Error'],
[MethodNotAllowedException, 'Method Not Allowed'],
[MisdirectedException, 'Misdirected'],
[NotAcceptableException, 'Not Acceptable'],
[NotFoundException, 'Not Found'],
[NotImplementedException, 'Not Implemented'],
[PayloadTooLargeException, 'Payload Too Large'],
[PreconditionFailedException, 'Precondition Failed'],
[RequestTimeoutException, 'Request Timeout'],
[ServiceUnavailableException, 'Service Unavailable'],
[UnauthorizedException, 'Unauthorized'],
[UnprocessableEntityException, 'Unprocessable Entity'],
[UnsupportedMediaTypeException, 'Unsupported Media Type'],
];

builtInExceptionsWithDefaults.forEach(
([ExceptionClass, expectedDescription]) => {
const error = new ExceptionClass('Custom message', {
cause: errorCause,
});

const response = error.getResponse() as {
message: string;
error: string;
};

expect(response.error).to.be.eql(
expectedDescription,
`${ExceptionClass.name} should have error "${expectedDescription}"`,
);
},
);
});
});
});