Skip to content

Commit 0a4e0f3

Browse files
committed
Add options to catch all errors
1 parent a5dfd8a commit 0a4e0f3

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/aws/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import type { APIGatewayEvent, APIGatewayProxyResult } from 'aws-lambda';
99
import HttpError from 'http-errors';
1010

1111
export interface TShallotErrorHandlerOptions extends Record<string, unknown> {
12-
logger?: (...args: string[]) => void;
12+
logger?: (...args: unknown[]) => void;
13+
catchAllErrors?: boolean;
1314
}
1415

1516
/**
@@ -36,6 +37,15 @@ const ShallotAWSHttpErrorHandler: ShallotMiddlewareWithOptions<
3637
statusCode: request.error.statusCode,
3738
body: request.error.message,
3839
};
40+
} else if (config.catchAllErrors) {
41+
if (config.logger != null) {
42+
config.logger(request.error);
43+
}
44+
45+
request.response = {
46+
statusCode: 500,
47+
body: 'Internal application server error',
48+
};
3949
}
4050
},
4151
});

0 commit comments

Comments
 (0)