From 8fbe7e81e6f0ebc9e8d2f9cb77b703c7ef0bd615 Mon Sep 17 00:00:00 2001 From: Iqpal Mannan Date: Fri, 15 Dec 2023 11:26:00 +0000 Subject: [PATCH 1/4] Return 404 error when LPA is not retrieved VEGA-2203 #minor --- docs/openapi/openapi.yaml | 29 +++++++++++++++++++++++++++++ internal/shared/problem.go | 6 ++++++ lambda/get/main.go | 2 +- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/docs/openapi/openapi.yaml b/docs/openapi/openapi.yaml index a76e8245..2300124e 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,29 @@ components: example: - source: "/uid" detail: "invalid uid format" + NotFoundError: + allOf: + - $ref: "#/components/schemas/AbstractError" + - type: object + properties: + code: + enum: ["NOT_FOUND"] + errors: + type: array + items: + type: object + required: + - source + - detail + properties: + source: + type: string + format: jsonpointer + detail: + type: string + example: + - source: "/uid" + detail: "uid 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..710bf36b 100644 --- a/lambda/get/main.go +++ b/lambda/get/main.go @@ -38,7 +38,7 @@ func (l *Lambda) HandleEvent(ctx context.Context, event events.APIGatewayProxyRe if err != nil { l.logger.Print(err) - return shared.ProblemInternalServerError.Respond() + return shared.ProblemNotFoundRequest.Respond() } body, err := json.Marshal(lpa) From e6f31f314b26007f2a614c42cddcfd0f868dcb01 Mon Sep 17 00:00:00 2001 From: Iqpal Mannan Date: Fri, 15 Dec 2023 12:06:23 +0000 Subject: [PATCH 2/4] Check lpa returned is empty as error not returned by DynamoDB VEGA-2203 #minor --- lambda/get/main.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lambda/get/main.go b/lambda/get/main.go index 710bf36b..a808458d 100644 --- a/lambda/get/main.go +++ b/lambda/get/main.go @@ -36,8 +36,10 @@ func (l *Lambda) HandleEvent(ctx context.Context, event events.APIGatewayProxyRe lpa, err := l.store.Get(ctx, event.PathParameters["uid"]) - if err != nil { - l.logger.Print(err) + // 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() } From 4eb8ce1a6d508d9a60d60e278617c10ee738015a Mon Sep 17 00:00:00 2001 From: Iqpal Mannan Date: Fri, 15 Dec 2023 12:18:22 +0000 Subject: [PATCH 3/4] 500 error if error is not null VEGA-2203 #minor --- lambda/get/main.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lambda/get/main.go b/lambda/get/main.go index a808458d..c0d7a1e9 100644 --- a/lambda/get/main.go +++ b/lambda/get/main.go @@ -43,6 +43,11 @@ func (l *Lambda) HandleEvent(ctx context.Context, event events.APIGatewayProxyRe return shared.ProblemNotFoundRequest.Respond() } + if err != nil { + l.logger.Print(err) + return shared.ProblemInternalServerError.Respond() + } + body, err := json.Marshal(lpa) if err != nil { From a31109420800c52caa384ba7ef7774828a09bede Mon Sep 17 00:00:00 2001 From: Iqpal Mannan Date: Fri, 15 Dec 2023 13:17:07 +0000 Subject: [PATCH 4/4] Field specific error message not required VEGA-2203 #minor --- docs/openapi/openapi.yaml | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/docs/openapi/openapi.yaml b/docs/openapi/openapi.yaml index 2300124e..7a2a4d3b 100644 --- a/docs/openapi/openapi.yaml +++ b/docs/openapi/openapi.yaml @@ -202,22 +202,6 @@ components: properties: code: enum: ["NOT_FOUND"] - errors: - type: array - items: - type: object - required: - - source - - detail - properties: - source: - type: string - format: jsonpointer - detail: - type: string - example: - - source: "/uid" - detail: "uid not found" Lpa: allOf: - $ref: "#/components/schemas/InitialLpa"