-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstateMachineResponses.ts
More file actions
64 lines (60 loc) · 1.93 KB
/
stateMachineResponses.ts
File metadata and controls
64 lines (60 loc) · 1.93 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
/* eslint-disable max-len */
/** VTL response template that unwraps successful workflow output and forwards status and headers. */
export const stateMachine200ResponseTemplate = `#set($payload = $util.parseJson($input.path('$.output')))
#set($context.responseOverride.status = $payload.Payload.statusCode)
#set($allHeaders = $payload.Payload.headers)
#foreach($headerName in $allHeaders.keySet())
#set($context.responseOverride.header[$headerName] = $allHeaders.get($headerName))
#end
$payload.Payload.body`
interface ErrorMap {
[key: string]: {
code: string
severity: string
diagnostics: string
codingCode: string
codingDisplay: string
}
}
const getOperationOutcome = (status: string) => {
const errorMap: ErrorMap = {
400: {
code: "value",
severity: "error",
diagnostics: "Invalid request.",
codingCode: "BAD_REQUEST",
codingDisplay: "400: The Server was unable to process the request"
},
500: {
code: "exception",
severity: "fatal",
diagnostics: "Unknown Error.",
codingCode: "SERVER_ERROR",
codingDisplay: "500: The Server has encountered an error processing the request."
}
}
return JSON.stringify({
ResourceType: "OperationOutcome",
issue: [
{
code: errorMap[status].code,
severity: errorMap[status].severity,
diagnostics: errorMap[status],
details: {
coding: [
{
system: "https://fhir.nhs.uk/CodeSystem/http-error-codes",
code: errorMap[status].codingCode,
display: errorMap[status].codingDisplay
}
]
}
}
]
})
}
/**
* @returns VTL response template that maps workflow failures to FHIR OperationOutcome payloads.
*/
export const stateMachineErrorResponseTemplate = (status: string) => `#set($context.responseOverride.header["Content-Type"] ="application/fhir+json")
${getOperationOutcome(status)}`