Skip to content

Commit 2cba6e1

Browse files
committed
update api error response to pass error message if Error
1 parent 1c9ddcf commit 2cba6e1

File tree

5 files changed

+18
-3
lines changed

5 files changed

+18
-3
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html)
66

7+
## [2.1.0]  (2020-01-04)
8+
9+
### Changed
10+
11+
- Api error response includes Error message if passed an Error object
12+
13+
### Fixed
14+
15+
- Removed extra files from published package
16+
- Correct package.json entry point to lib
17+
718
## [2.0.1]  (2020-01-04)
819

920
### Fixed
@@ -126,6 +137,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/),
126137
- Update older libraries
127138
- Now publish from Git tags instead of master pushes
128139

140+
[2.1.0]: https://github.com/manwaring/lambda-wrapper/compare/v2.0.1...v2.1.0
129141
[2.0.1]: https://github.com/manwaring/lambda-wrapper/compare/v2.0.0...v2.0.1
130142
[2.0.0]: https://github.com/manwaring/lambda-wrapper/compare/v1.2.2...v2.0.0
131143
[1.2.2]: https://github.com/manwaring/lambda-wrapper/compare/v1.2.1...v1.2.2

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@manwaring/lambda-wrapper",
33
"description": "A lambda handler wrapper to abstract common functionality and provide useful defaults",
4-
"version": "2.0.1",
4+
"version": "2.1.0",
55
"scripts": {
66
"publish-please-dry-run": "publish-please --dry-run",
77
"publish-please": "publish-please",

src/api/responses.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('API responses', () => {
4040
});
4141

4242
it('Handles error response', () => {
43-
const response = error('error');
43+
const response = error(new Error('error'));
4444
expect(response).toEqual({
4545
headers: { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Credentials': true },
4646
body: JSON.stringify({ message: 'error' }),

src/api/responses.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ export function notFound(message?: string): ApiResponse {
3636

3737
export function error(message?: any): ApiResponse {
3838
const response = { statusCode: 503, headers: DEFAULT_HEADERS };
39+
if (message && message instanceof Error) {
40+
message = message.message;
41+
}
3942
if (message) {
4043
response['body'] = JSON.stringify({ message });
4144
}

0 commit comments

Comments
 (0)