Skip to content

Commit

Permalink
fix: do not return empty JSON object if no content
Browse files Browse the repository at this point in the history
  • Loading branch information
Lenakh97 committed Jul 2, 2024
1 parent aef1405 commit 8846fd1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion api/res.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { APIGatewayProxyResultV2 } from 'aws-lambda'

export const res =
(statusCode: number, options?: { expires: number }) =>
(body: unknown): APIGatewayProxyResultV2 => ({
(body?: unknown): APIGatewayProxyResultV2 => ({
statusCode,
headers: {
'Access-Control-Allow-Origin': '*',
Expand Down
8 changes: 4 additions & 4 deletions lambda/getBasicInformationLambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,22 @@ export const handler = async (
const onomondoRegex = /89(\d{0,2})73/
const isOnomondoIccid = onomondoRegex.test(iccid)
if (isOnomondoIccid === false) {
return res(toStatusCode[ErrorType.EntityNotFound], { expires: 60 })({})
return res(toStatusCode[ErrorType.EntityNotFound], { expires: 60 })()
}
const maybeSimDetails = await getSimDetailsFromCacheFunc(iccid)
if ('error' in maybeSimDetails) {
//No information about SIM in Cache
if (maybeSimDetails.error instanceof SIMNotFoundError) {
await q({ payload: iccid, deduplicationId: iccid })
return res(toStatusCode[ErrorType.Conflict], { expires: 60 })({})
return res(toStatusCode[ErrorType.Conflict], { expires: 60 })()
}
//SIM not existing
else if (maybeSimDetails.error instanceof SIMNotExistingError) {
return res(toStatusCode[ErrorType.EntityNotFound], { expires: 60 })({})
return res(toStatusCode[ErrorType.EntityNotFound], { expires: 60 })()
}
console.error('Internal Error: ', maybeSimDetails.error)
//Internal Error
return res(toStatusCode[ErrorType.InternalError], { expires: 60 })({})
return res(toStatusCode[ErrorType.InternalError], { expires: 60 })()
}
//Case 2: old data in DynamoDB (> 5min)
const timeStampFromDB = maybeSimDetails.success.timestamp
Expand Down

0 comments on commit 8846fd1

Please sign in to comment.