Skip to content

Commit 34405f7

Browse files
committed
update not authorized 403 -> 401
1 parent 1f2c796 commit 34405f7

File tree

6 files changed

+29
-22
lines changed

6 files changed

+29
-22
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ 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+
## [3.5.0]  (2020-05-10)
8+
9+
### Changed
10+
11+
- API response 'not authorized' now returns 401 instead of 403
12+
713
## [3.4.0]  (2020-05-10)
814

915
### Added
@@ -213,6 +219,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/),
213219
- Update older libraries
214220
- Now publish from Git tags instead of master pushes
215221

222+
[3.5.0]: https://github.com/manwaring/lambda-wrapper/compare/v3.4.0...v3.5.0
216223
[3.4.0]: https://github.com/manwaring/lambda-wrapper/compare/v3.3.3...v3.4.0
217224
[3.3.3]: https://github.com/manwaring/lambda-wrapper/compare/v3.3.1...v3.3.3
218225
[3.3.2]: https://github.com/manwaring/lambda-wrapper/compare/v3.3.1...v3.3.2

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export interface ApiSignature<T> {
114114
success(payload?: any, replacer?: (this: any, key: string, value: any) => any): ApiResponse; // returns 200 status code with optional payload as body
115115
invalid(errors?: string[]): ApiResponse; // returns 400 status code with optional errors as body
116116
notFound(message?: string): ApiResponse; // returns 404 status code with optional message as body
117-
notAuthorized(message?: string): ApiResponse; // returns 403 status code with optional message as body
117+
notAuthorized(message?: string): ApiResponse; // returns 401 status code with optional message as body
118118
redirect(url: string): ApiResponse; // returns 302 status code (redirect) with new url
119119
error(error?: any): ApiResponse; // returns 500 status code with optional error as body
120120
}

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": "3.4.0",
4+
"version": "3.5.0",
55
"scripts": {
66
"publish-please-dry-run": "publish-please --dry-run",
77
"publish-please": "publish-please",

src/api/responses.test.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ describe('API responses', () => {
1212
headers: {
1313
'Access-Control-Allow-Origin': '*',
1414
'Access-Control-Allow-Credentials': true,
15-
'Content-Type': 'application/json'
15+
'Content-Type': 'application/json',
1616
},
17-
statusCode: 200
17+
statusCode: 200,
1818
});
1919
});
2020

2121
it('Handles success response without payload', () => {
2222
const response = success();
2323
expect(response).toEqual({
2424
headers: { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Credentials': true },
25-
statusCode: 200
25+
statusCode: 200,
2626
});
2727
});
2828

@@ -40,10 +40,10 @@ describe('API responses', () => {
4040
headers: {
4141
'Access-Control-Allow-Origin': '*',
4242
'Access-Control-Allow-Credentials': true,
43-
'Content-Type': 'application/json'
43+
'Content-Type': 'application/json',
4444
},
4545
body: JSON.stringify({ hello: 'world', replace: { not: 'this one' } }),
46-
statusCode: 200
46+
statusCode: 200,
4747
});
4848
});
4949

@@ -53,10 +53,10 @@ describe('API responses', () => {
5353
headers: {
5454
'Access-Control-Allow-Origin': '*',
5555
'Access-Control-Allow-Credentials': true,
56-
'Content-Type': 'application/json'
56+
'Content-Type': 'application/json',
5757
},
5858
body: JSON.stringify({ message: 'error' }),
59-
statusCode: 500
59+
statusCode: 500,
6060
});
6161
});
6262

@@ -67,9 +67,9 @@ describe('API responses', () => {
6767
headers: {
6868
'Access-Control-Allow-Origin': '*',
6969
'Access-Control-Allow-Credentials': true,
70-
'Content-Type': 'application/json'
70+
'Content-Type': 'application/json',
7171
},
72-
statusCode: 400
72+
statusCode: 400,
7373
});
7474
});
7575

@@ -78,9 +78,9 @@ describe('API responses', () => {
7878
expect(response).toEqual({
7979
headers: {
8080
'Access-Control-Allow-Origin': '*',
81-
'Access-Control-Allow-Credentials': true
81+
'Access-Control-Allow-Credentials': true,
8282
},
83-
statusCode: 400
83+
statusCode: 400,
8484
});
8585
});
8686

@@ -91,9 +91,9 @@ describe('API responses', () => {
9191
headers: {
9292
'Access-Control-Allow-Origin': '*',
9393
'Access-Control-Allow-Credentials': true,
94-
'Content-Type': 'application/json'
94+
'Content-Type': 'application/json',
9595
},
96-
statusCode: 404
96+
statusCode: 404,
9797
});
9898
});
9999

@@ -104,9 +104,9 @@ describe('API responses', () => {
104104
headers: {
105105
'Access-Control-Allow-Origin': '*',
106106
'Access-Control-Allow-Credentials': true,
107-
'Content-Type': 'application/json'
107+
'Content-Type': 'application/json',
108108
},
109-
statusCode: 403
109+
statusCode: 401,
110110
});
111111
});
112112

@@ -116,9 +116,9 @@ describe('API responses', () => {
116116
headers: {
117117
'Access-Control-Allow-Origin': '*',
118118
'Access-Control-Allow-Credentials': true,
119-
Location: 'url'
119+
Location: 'url',
120120
},
121-
statusCode: 302
121+
statusCode: 302,
122122
});
123123
});
124124
});

src/api/responses.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Metrics, logger } from '../common';
22

33
const DEFAULT_HEADERS = {
44
'Access-Control-Allow-Origin': '*',
5-
'Access-Control-Allow-Credentials': true
5+
'Access-Control-Allow-Credentials': true,
66
};
77

88
const metrics = new Metrics('API Gateway');
@@ -38,7 +38,7 @@ export function notFound(message?: string): ApiResponse {
3838
}
3939

4040
export function notAuthorized(message?: string): ApiResponse {
41-
const response = { statusCode: 403, headers: { ...DEFAULT_HEADERS } };
41+
const response = { statusCode: 401, headers: { ...DEFAULT_HEADERS } };
4242
if (message) {
4343
response['body'] = JSON.stringify({ message });
4444
response.headers['Content-Type'] = 'application/json';

0 commit comments

Comments
 (0)