Skip to content

Commit 16f1076

Browse files
committed
fix(LambdaHandlerError): allow details to be passed as string array
1 parent 7b416a7 commit 16f1076

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/error/LambdaHandlerError.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export abstract class LambdaHandlerError extends Error {
2-
public constructor(public details?: string) {
3-
super(details);
2+
public constructor(public details?: string | string[]) {
3+
super(details ? String(details) : undefined);
44
}
55
}

src/response.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,22 @@ import {
1212
} from "./error";
1313
import { ConflictError } from "./error/ConflictError";
1414

15+
type Details = string | string[] | undefined;
1516
export interface APIGatewayResponse extends Omit<APIGatewayProxyResult, "body"> {
1617
body: unknown | undefined;
1718
}
1819

19-
export function badRequest(details: string | undefined): APIGatewayResponse {
20+
export function badRequest(details: Details): APIGatewayResponse {
2021
const error: BadRequestError = new BadRequestError(details);
2122
return buildResult<BadRequestError>(error, constants.HTTP_STATUS_BAD_REQUEST);
2223
}
2324

24-
export function forbidden(details: string | undefined): APIGatewayResponse {
25+
export function forbidden(details: Details): APIGatewayResponse {
2526
const error: ForbiddenError = new ForbiddenError(details);
2627
return buildResult<ForbiddenError>(error, constants.HTTP_STATUS_FORBIDDEN);
2728
}
2829

29-
export function unauthorized(details: string | undefined): APIGatewayResponse {
30+
export function unauthorized(details: Details): APIGatewayResponse {
3031
const error: UnauthorizedError = new UnauthorizedError(details);
3132
return buildResult<UnauthorizedError>(error, constants.HTTP_STATUS_UNAUTHORIZED);
3233
}
@@ -36,22 +37,22 @@ export function internalServerError(): APIGatewayResponse {
3637
return buildResult<InternalServerError>(error, constants.HTTP_STATUS_INTERNAL_SERVER_ERROR);
3738
}
3839

39-
export function notFound(details: string | undefined): APIGatewayResponse {
40+
export function notFound(details: Details): APIGatewayResponse {
4041
const error: NotFoundError = new NotFoundError(details);
4142
return buildResult<NotFoundError>(error, constants.HTTP_STATUS_NOT_FOUND);
4243
}
4344

44-
export function requestTimeout(details: string | undefined): APIGatewayResponse {
45+
export function requestTimeout(details: Details): APIGatewayResponse {
4546
const error: RequestTimeoutError = new RequestTimeoutError(details);
4647
return buildResult<RequestTimeoutError>(error, constants.HTTP_STATUS_REQUEST_TIMEOUT);
4748
}
4849

49-
export function unprocessableEntity(details: string | undefined): APIGatewayResponse {
50+
export function unprocessableEntity(details: Details): APIGatewayResponse {
5051
const error: UnprocessableEntityError = new UnprocessableEntityError(details);
5152
return buildResult<UnprocessableEntityError>(error, constants.HTTP_STATUS_UNPROCESSABLE_ENTITY);
5253
}
5354

54-
export function conflict(details: string | undefined): APIGatewayResponse {
55+
export function conflict(details: Details): APIGatewayResponse {
5556
const error: ConflictError = new ConflictError(details);
5657
return buildResult<ConflictError>(error, constants.HTTP_STATUS_CONFLICT);
5758
}

0 commit comments

Comments
 (0)