Skip to content

Commit

Permalink
Gotta do error handling in our function instead of API Gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
tmclaugh committed Oct 22, 2024
1 parent d5b2a34 commit 6f6856b
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/handlers/CreateEntity/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,19 @@ export async function handler (event: APIGatewayProxyEvent, _: Context): Promise
LOGGER.info('Received event', { event })

const entity: Entity = JSON.parse(event.body || '{}') // Already validated body at Gateway
const output = await putEntity(entity)

let statusCode: number
let body: string
let output: PutItemCommandOutput
try {
output = await putEntity(entity)
statusCode = 201
body = JSON.stringify({'request_id': output.$metadata.requestId})
} catch (error) {
statusCode = 500
body = JSON.stringify({error: (<Error>error).message})
}


return {
statusCode: 201,
Expand Down

0 comments on commit 6f6856b

Please sign in to comment.