Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow any status code in builder functions #357

Merged
merged 3 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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