From 4f51b6e1b9414862d1f488f4479f02919226e600 Mon Sep 17 00:00:00 2001 From: iqpalm <62601059+iqpalm@users.noreply.github.com> Date: Mon, 18 Dec 2023 10:40:37 +0000 Subject: [PATCH] VEGA-2203 LPA Store returns 500 if it can't find an LPA (#74) * Return 404 error when LPA is not retrieved VEGA-2203 #minor * Check lpa returned is empty as error not returned by DynamoDB VEGA-2203 #minor * 500 error if error is not null VEGA-2203 #minor * Field specific error message not required VEGA-2203 #minor --------- Co-authored-by: Iqpal Mannan --- docs/openapi/openapi.yaml | 13 +++++++++++++ internal/shared/problem.go | 6 ++++++ lambda/get/main.go | 7 +++++++ 3 files changed, 26 insertions(+) diff --git a/docs/openapi/openapi.yaml b/docs/openapi/openapi.yaml index 1a18feff..6d72d196 100644 --- a/docs/openapi/openapi.yaml +++ b/docs/openapi/openapi.yaml @@ -68,6 +68,12 @@ paths: application/json: schema: $ref: "#/components/schemas/BadRequestError" + "404": + description: Case not found. + content: + application/json: + schema: + $ref: "#/components/schemas/NotFoundError" x-amazon-apigateway-auth: type: "AWS_IAM" x-amazon-apigateway-integration: @@ -189,6 +195,13 @@ components: example: - source: "/uid" detail: "invalid uid format" + NotFoundError: + allOf: + - $ref: "#/components/schemas/AbstractError" + - type: object + properties: + code: + enum: ["NOT_FOUND"] Lpa: allOf: - $ref: "#/components/schemas/InitialLpa" diff --git a/internal/shared/problem.go b/internal/shared/problem.go index 57fac580..890a1883 100644 --- a/internal/shared/problem.go +++ b/internal/shared/problem.go @@ -48,6 +48,12 @@ var ProblemUnauthorisedRequest Problem = Problem{ Detail: "Invalid JWT", } +var ProblemNotFoundRequest Problem = Problem{ + StatusCode: 404, + Code: "NOT_FOUND", + Detail: "Record not found", +} + func (problem Problem) Respond() (events.APIGatewayProxyResponse, error) { var errorString = "" for _, ve := range problem.Errors { diff --git a/lambda/get/main.go b/lambda/get/main.go index c9cc7e47..c0d7a1e9 100644 --- a/lambda/get/main.go +++ b/lambda/get/main.go @@ -36,6 +36,13 @@ func (l *Lambda) HandleEvent(ctx context.Context, event events.APIGatewayProxyRe lpa, err := l.store.Get(ctx, event.PathParameters["uid"]) + // If item can't be found in DynamoDB then it returns empty object hence 404 error returned if + // empty object returned + if lpa.Uid == "" { + l.logger.Print("Uid not found") + return shared.ProblemNotFoundRequest.Respond() + } + if err != nil { l.logger.Print(err) return shared.ProblemInternalServerError.Respond()