From 060e9e35ce81ffa9962be4ebd0f6e53b52e4cdc9 Mon Sep 17 00:00:00 2001 From: Lena Haraldseid Date: Tue, 2 Jul 2024 08:59:47 +0200 Subject: [PATCH] wip --- api/res.ts | 4 ++-- lambda/getBasicInformationLambda.ts | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/api/res.ts b/api/res.ts index f9ad753a..33f43cd3 100644 --- a/api/res.ts +++ b/api/res.ts @@ -1,12 +1,12 @@ import type { APIGatewayProxyResultV2 } from 'aws-lambda' export const res = - (statusCode: number, options?: { expires: number }) => + (statusCode: number, options?: { expires: number; contentType?: string }) => (body: unknown): APIGatewayProxyResultV2 => ({ statusCode, headers: { 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', + 'Content-Type': options?.contentType ?? 'application/json', ...(options?.expires !== undefined && { 'Cache-Control': `public, max-age=${options.expires}`, Expires: new Date( diff --git a/lambda/getBasicInformationLambda.ts b/lambda/getBasicInformationLambda.ts index a3669253..860e234d 100644 --- a/lambda/getBasicInformationLambda.ts +++ b/lambda/getBasicInformationLambda.ts @@ -40,7 +40,10 @@ export const handler = async ( //Check if iccid is existing const issuer = identifyIssuer(iccid) if (issuer === undefined) { - return res(toStatusCode[ErrorType.BadRequest], { expires: 60 })({ + return res(toStatusCode[ErrorType.BadRequest], { + expires: 60, + contentType: 'application/problem+json', + })({ type: 'https://example.net/validation-error', title: "Your request parameters didn't validate.", 'invalid-params': [ @@ -55,7 +58,10 @@ export const handler = async ( //Check if iccid from a valid issuer const isValidIccid = validIssuers.includes(issuer.issuerIdentifierNumber) if (isValidIccid === false) { - return res(toStatusCode[ErrorType.BadRequest], { expires: 60 })({ + return res(toStatusCode[ErrorType.BadRequest], { + expires: 60, + contentType: 'application/problem+json', + })({ type: 'https://example.net/validation-error', title: "Your request parameters didn't validate.", 'invalid-params': [