Skip to content

Commit 5775932

Browse files
authored
ELI-397: AWS api gateway to handle bad request param error (#291)
1 parent 03d4cfb commit 5775932

1 file changed

Lines changed: 45 additions & 6 deletions

File tree

infrastructure/stacks/api-layer/patient_check.tf

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
resource "aws_api_gateway_request_validator" "patient_check_validator" {
32
rest_api_id = module.eligibility_signposting_api_gateway.rest_api_id
43
name = "validate-path-params"
@@ -27,12 +26,12 @@ resource "aws_api_gateway_method" "get_patient_check" {
2726
}
2827

2928
resource "aws_api_gateway_integration" "get_patient_check" {
30-
rest_api_id = module.eligibility_signposting_api_gateway.rest_api_id
31-
resource_id = aws_api_gateway_resource.patient.id
32-
http_method = aws_api_gateway_method.get_patient_check.http_method
29+
rest_api_id = module.eligibility_signposting_api_gateway.rest_api_id
30+
resource_id = aws_api_gateway_resource.patient.id
31+
http_method = aws_api_gateway_method.get_patient_check.http_method
3332
integration_http_method = "POST" # Needed for lambda proxy integration
34-
type = "AWS_PROXY"
35-
uri = module.eligibility_signposting_lambda_function.aws_lambda_invoke_arn
33+
type = "AWS_PROXY"
34+
uri = module.eligibility_signposting_lambda_function.aws_lambda_invoke_arn
3635

3736
depends_on = [
3837
aws_api_gateway_method.get_patient_check
@@ -47,3 +46,43 @@ resource "aws_lambda_permission" "get_patient_check" {
4746

4847
source_arn = "${module.eligibility_signposting_api_gateway.execution_arn}/*/*"
4948
}
49+
50+
resource "aws_api_gateway_gateway_response" "bad_request_parameters" {
51+
rest_api_id = module.eligibility_signposting_api_gateway.rest_api_id
52+
response_type = "BAD_REQUEST_PARAMETERS"
53+
status_code = "400"
54+
55+
response_templates = {
56+
"application/json" = jsonencode({
57+
resourceType = "OperationOutcome"
58+
id = "$context.requestId"
59+
meta = {
60+
lastUpdated = "$context.requestTime"
61+
}
62+
issue = [
63+
{
64+
severity = "error"
65+
code = "invalid"
66+
details = {
67+
coding = [
68+
{
69+
system = "https://fhir.nhs.uk/STU3/ValueSet/Spine-ErrorOrWarningCode-1",
70+
code = "BAD_REQUEST",
71+
display = "Bad Request"
72+
}
73+
]
74+
}
75+
diagnostics = "Missing required NHS Number from path parameters",
76+
location = [
77+
"parameters/id"
78+
]
79+
}
80+
]
81+
})
82+
}
83+
84+
response_parameters = {
85+
"gatewayresponse.header.Access-Control-Allow-Origin" = "'*'"
86+
"gatewayresponse.header.Content-Type" = "'application/fhir+json'"
87+
}
88+
}

0 commit comments

Comments
 (0)