Skip to content

Commit 0264c17

Browse files
authoredAug 16, 2022
feat: Allow any status code in builder functions (#357)
🎉 Thanks for sending this pull request! 🎉 Which problem is this pull request solving? There are requests to cache any status codes for builder functions. List other issues or pull requests related to this problem netlify/pillar-runtime#443 Describe the solution you've chosen We're removing the status check here, but our invocation proxy still has some checks in place. Describe alternatives you've considered n/a Checklist I have read the contribution guidelines. The status checks are successful (continuous integration). Those can be seen below.
1 parent af5d8ab commit 0264c17

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed
 

‎src/lib/builder.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { HandlerContext, HandlerEvent } from '../function'
44
import { BuilderHandler, Handler, HandlerCallback } from '../function/handler'
55
import { Response, BuilderResponse } from '../function/response'
66

7-
import { BUILDER_FUNCTIONS_FLAG, HTTP_STATUS_METHOD_NOT_ALLOWED, HTTP_STATUS_OK, METADATA_VERSION } from './consts'
7+
import { BUILDER_FUNCTIONS_FLAG, HTTP_STATUS_METHOD_NOT_ALLOWED, METADATA_VERSION } from './consts'
88

99
const augmentResponse = (response: BuilderResponse) => {
10-
if (!response || response.statusCode !== HTTP_STATUS_OK) {
10+
if (!response) {
1111
return response
1212
}
1313
const metadata = { version: METADATA_VERSION, builder_function: BUILDER_FUNCTIONS_FLAG, ttl: response.ttl ?? 0 }

‎test/builder.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ test('Injects the metadata object into a synchronous handler', async (t) => {
3939
t.deepEqual(response, { ...originalResponse, ...METADATA_OBJECT })
4040
})
4141

42-
test('Does not inject the metadata object for non-200 responses', async (t) => {
42+
test('Injects the metadata object for non-200 responses', async (t) => {
4343
const originalResponse = {
4444
body: ':thumbsdown:',
4545
statusCode: 404,
@@ -55,7 +55,7 @@ test('Does not inject the metadata object for non-200 responses', async (t) => {
5555
}
5656
const response = await invokeLambda(builder(myHandler))
5757

58-
t.deepEqual(response, originalResponse)
58+
t.deepEqual(response, { ...originalResponse, ...METADATA_OBJECT })
5959
})
6060

6161
test('Returns a 405 error for requests using the POST method', async (t) => {

0 commit comments

Comments
 (0)