-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patherrors.ts
More file actions
68 lines (62 loc) · 2.24 KB
/
errors.ts
File metadata and controls
68 lines (62 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
export interface ApiError {
id: string;
code: ApiErrorCode;
links: {
about: "https://digital.nhs.uk/developer/api-catalogue/nhs-notify-supplier";
};
status: ApiErrorStatus;
title: ApiErrorTitle;
detail: ApiErrorDetail | string;
}
export enum ApiErrorCode {
InternalServerError = "NOTIFY_INTERNAL_SERVER_ERROR",
InvalidRequest = "NOTIFY_INVALID_REQUEST",
NotFound = "NOTIFY_NOT_FOUND",
}
export enum ApiErrorTitle {
InternalServerError = "Internal server error",
InvalidRequest = "Invalid request",
NotFound = "Not found",
}
export enum ApiErrorStatus {
InternalServerError = "500",
InvalidRequest = "400",
NotFound = "404",
}
export enum ApiErrorDetail {
NotFoundId = "No resource found with that ID",
InvalidRequestMissingBody = "The request is missing the body",
InvalidRequestMissingLetterIdPathParameter = "The request is missing the letter id path parameter",
InvalidRequestLetterIdsMismatch = "The letter ID in the request body does not match the letter ID path parameter",
InvalidRequestMissingMiIdPathParameter = "The request is missing the mi id path parameter",
InvalidRequestBody = "The request body is invalid",
InvalidRequestLimitNotANumber = "The limit parameter is not a number",
InvalidRequestLimitNotInRange = "The limit parameter must be a positive number not greater than %s",
InvalidRequestLimitOnly = "Only 'limit' query parameter is supported",
InvalidRequestNoRequestId = "The request does not contain a request id",
InvalidRequestTimestamp = "Timestamps should be UTC date/times in ISO8601 format, with a Z suffix",
InvalidRequestLettersToUpdate = "The request exceeds the maximum of %s items allowed for update",
InvalidRequestDuplicateLetterId = "The request cannot include multiple letter objects with the same id",
}
export function buildApiError(params: {
id: string;
code: ApiErrorCode;
status: ApiErrorStatus;
title: ApiErrorTitle;
detail: ApiErrorDetail | string;
}): ApiError {
return {
id: params.id,
code: params.code,
links: {
about:
"https://digital.nhs.uk/developer/api-catalogue/nhs-notify-supplier",
},
status: params.status,
title: params.title,
detail: params.detail,
};
}
export interface ErrorResponse {
errors: ApiError[];
}