Skip to content

Commit

Permalink
feat: Allow any status code in builder functions (#357)
Browse files Browse the repository at this point in the history
🎉 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.
  • Loading branch information
mraerino authored Aug 16, 2022
1 parent af5d8ab commit 0264c17
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/lib/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { HandlerContext, HandlerEvent } from '../function'
import { BuilderHandler, Handler, HandlerCallback } from '../function/handler'
import { Response, BuilderResponse } from '../function/response'

import { BUILDER_FUNCTIONS_FLAG, HTTP_STATUS_METHOD_NOT_ALLOWED, HTTP_STATUS_OK, METADATA_VERSION } from './consts'
import { BUILDER_FUNCTIONS_FLAG, HTTP_STATUS_METHOD_NOT_ALLOWED, METADATA_VERSION } from './consts'

const augmentResponse = (response: BuilderResponse) => {
if (!response || response.statusCode !== HTTP_STATUS_OK) {
if (!response) {
return response
}
const metadata = { version: METADATA_VERSION, builder_function: BUILDER_FUNCTIONS_FLAG, ttl: response.ttl ?? 0 }
Expand Down
4 changes: 2 additions & 2 deletions test/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ test('Injects the metadata object into a synchronous handler', async (t) => {
t.deepEqual(response, { ...originalResponse, ...METADATA_OBJECT })
})

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

t.deepEqual(response, originalResponse)
t.deepEqual(response, { ...originalResponse, ...METADATA_OBJECT })
})

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

0 comments on commit 0264c17

Please sign in to comment.