Skip to content

Commit d0ae003

Browse files
Marry errors with OAS
1 parent 2761b90 commit d0ae003

File tree

6 files changed

+27
-4
lines changed

6 files changed

+27
-4
lines changed

lambdas/api-handler/src/contracts/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export enum ApiErrorStatus {
2626
}
2727

2828
export enum ApiErrorDetail {
29-
NotFoundLetterId = 'The provided letter ID does not exist for the supplier',
29+
NotFoundLetterId = 'No resource found with that ID',
3030
InvalidRequestMissingSupplierId = 'The supplier ID is missing from the request',
3131
InvalidRequestMissingBody = 'The request is missing the body',
3232
InvalidRequestMissingLetterIdPathParameter = 'The request is missing the letter id path parameter',

lambdas/api-handler/src/mappers/__tests__/error-mapper.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe("mapErrorToResponse", () => {
3535
"errors": [
3636
{
3737
"code": "NOTIFY_LETTER_NOT_FOUND",
38-
"detail": "The provided letter ID does not exist for the supplier",
38+
"detail": "No resource found with that ID",
3939
"id": expect.any(String),
4040
"links": {
4141
"about": "https://digital.nhs.uk/developer/api-catalogue/nhs-notify-supplier"

lambdas/api-handler/src/services/__tests__/letter-operations.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ describe('patchLetterStatus function', () => {
8787
updateLetterStatus: jest.fn().mockRejectedValue(new Error('Letter with id l1 not found for supplier s1'))
8888
};
8989

90-
await expect(patchLetterStatus(letterResource, 'letter1', 'supplier1', mockRepo as any)).rejects.toThrow("The provided letter ID does not exist");
90+
await expect(patchLetterStatus(letterResource, 'letter1', 'supplier1', mockRepo as any)).rejects.toThrow("No resource found with that ID");
9191
});
9292

9393
it('should throw unexpected error', async () => {

specification/api/components/endpoints/patchLetter.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ responses:
77
"200":
88
$ref: "../responses/patchLetter200.yml"
99
"400":
10-
$ref: "../responses/errors/badRequest.yml"
10+
$ref: "../responses/errors/patchLetter/patchLetterBadRequest.yml"
1111
"404":
1212
$ref: "../responses/errors/resourceNotFound.yml"
1313
"429":
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"errors": [
3+
{
4+
"code": "NOTIFY_INVALID_REQUEST",
5+
"detail": "The request body is invalid",
6+
"id": "rrt-1931948104716186917-c-geu2-10664-3111479-3.0",
7+
"links": {
8+
"about": "https://digital.nhs.uk/developer/api-catalogue/nhs-notify-supplier"
9+
},
10+
"status": "400",
11+
"title": "Invalid request"
12+
}
13+
]
14+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
description: "Bad request, invalid input data"
2+
content:
3+
application/vnd.api+json:
4+
schema:
5+
$ref: "../../../schemas/errorResponse.yml"
6+
examples:
7+
error-bad-request-invalid-request-body:
8+
value:
9+
$ref: ../../../examples/errors/responses/patchLetter/invalidBody.json

0 commit comments

Comments
 (0)