From 6f6856bcd686fe7a08292e6a66f10e959c8bd139 Mon Sep 17 00:00:00 2001 From: Tom McLaughlin Date: Tue, 22 Oct 2024 14:29:45 -0400 Subject: [PATCH] Gotta do error handling in our function instead of API Gateway --- src/handlers/CreateEntity/function.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/handlers/CreateEntity/function.ts b/src/handlers/CreateEntity/function.ts index 94f4075..fbb68cc 100644 --- a/src/handlers/CreateEntity/function.ts +++ b/src/handlers/CreateEntity/function.ts @@ -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).message}) + } + return { statusCode: 201,