diff --git a/docs/openapi/openapi.yaml b/docs/openapi/openapi.yaml index a76e8245..7a2a4d3b 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()