Skip to content

Commit

Permalink
tidy up our logging too
Browse files Browse the repository at this point in the history
  • Loading branch information
tmclaugh committed Oct 22, 2024
1 parent 2968874 commit ed7a9c7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
12 changes: 7 additions & 5 deletions src/handlers/CreateEntity/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ export async function putEntity(entity: Entity): Promise<PutItemCommandOutput> {
try {
const command = new PutItemCommand(params)
output = await DDB_CLIENT.send(command)
LOGGER.info('PutItemCommand succeeded', { output })
LOGGER.debug('PutItemCommand succeeded', { output })
} catch (error) {
LOGGER.error('PutItemCommand failed', {
error: (<DynamoDBServiceException>error).name,
message: error
LOGGER.error({
name: (<DynamoDBServiceException>error).name,
message: (<DynamoDBServiceException>error).message,
error: <DynamoDBServiceException>error,
})
throw error
}
Expand All @@ -69,7 +70,7 @@ export async function putEntity(entity: Entity): Promise<PutItemCommandOutput> {


export async function handler (event: APIGatewayProxyEvent, _: Context): Promise<APIGatewayProxyResult> {
LOGGER.info('Received event', { event })
LOGGER.debug('Received event', { event })

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

Expand All @@ -80,6 +81,7 @@ export async function handler (event: APIGatewayProxyEvent, _: Context): Promise
statusCode = 201
body = JSON.stringify({'request_id': output.$metadata.requestId})
} catch (error) {
LOGGER.error("Operation failed", { event })
const fault = (<DynamoDBServiceException>error).$fault
switch (fault) {
case 'client':
Expand Down
14 changes: 8 additions & 6 deletions src/handlers/DeleteEntity/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ export async function deleteEntity(
try {
const command = new DeleteItemCommand(params)
output = await DDB_CLIENT.send(command)
LOGGER.info('DeleteItemCommand succeeded', { output })
LOGGER.debug('DeleteItemCommand succeeded', { output })
} catch (error) {
LOGGER.error('DeleteItemCommand failed', {
error: (<DynamoDBServiceException>error).name,
message: error
})
LOGGER.error({
error: <DynamoDBServiceException>error,
name: (<DynamoDBServiceException>error).name,
message: (<DynamoDBServiceException>error).message,
})
throw error
}

Expand All @@ -52,7 +53,7 @@ export async function deleteEntity(


export async function handler (event: APIGatewayProxyEvent, _: Context): Promise<APIGatewayProxyResult> {
LOGGER.info('Received event', { event })
LOGGER.debug('Received event', { event })

const namespace = event.pathParameters?.namespace as string
const kind = event.pathParameters?.kind as string
Expand All @@ -69,6 +70,7 @@ export async function handler (event: APIGatewayProxyEvent, _: Context): Promise
statusCode = 200
body = JSON.stringify(entity)
} catch (error) {
LOGGER.error("Operation failed", { event })
const fault = (<DynamoDBServiceException>error).$fault
switch (fault) {
case 'client':
Expand Down
14 changes: 8 additions & 6 deletions src/handlers/GetEntity/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ export async function getEntity(
try {
const command = new GetItemCommand(params)
output = await DDB_CLIENT.send(command)
LOGGER.info('GetItemCommand succeeded', { output })
LOGGER.debug('GetItemCommand succeeded', { output })
} catch (error) {
LOGGER.error('GetItemCommand failed', {
error: (<DynamoDBServiceException>error).name,
message: error
})
LOGGER.error({
error: <DynamoDBServiceException>error,
name: (<DynamoDBServiceException>error).name,
message: (<DynamoDBServiceException>error).message,
})
throw error
}

Expand All @@ -64,7 +65,7 @@ export async function getEntity(


export async function handler (event: APIGatewayProxyEvent, _: Context): Promise<APIGatewayProxyResult> {
LOGGER.info('Received event', { event })
LOGGER.debug('Received event', { event })

const namespace = event.pathParameters?.namespace as string
const kind = event.pathParameters?.kind as string
Expand All @@ -81,6 +82,7 @@ export async function handler (event: APIGatewayProxyEvent, _: Context): Promise
statusCode = 200
body = JSON.stringify(entity)
} catch (error) {
LOGGER.error("Operation failed", { event })
const fault = (<DynamoDBServiceException>error).$fault
switch (fault) {
case 'client':
Expand Down

0 comments on commit ed7a9c7

Please sign in to comment.