Skip to content

Commit

Permalink
Add 500 Fault rule and update all errors to have correct mime type
Browse files Browse the repository at this point in the history
  • Loading branch information
JackPlowman committed May 7, 2024
1 parent 0cc5137 commit ff3a308
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 14 deletions.
10 changes: 0 additions & 10 deletions proxies/live/apiproxy/policies/RaiseFault.400BadRequest.xml

This file was deleted.

8 changes: 5 additions & 3 deletions proxies/live/apiproxy/policies/RaiseFault.401Unauthorized.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
<Properties/>
<FaultResponse>
<Set>
<Headers/>
<Headers>
<Header name="Content-Type">application/fhir+json</Header>
</Headers>
<StatusCode>401</StatusCode>
<ReasonPhrase>Unauthorized</ReasonPhrase>
<Payload>
Expand All @@ -35,9 +37,9 @@
}
],
"resourceType": "OperationOutcome"
}
}
</Payload>
</Set>
</FaultResponse>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</RaiseFault>
</RaiseFault>
4 changes: 3 additions & 1 deletion proxies/live/apiproxy/policies/RaiseFault.404NotFound.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
<Properties/>
<FaultResponse>
<Set>
<Headers/>
<Headers>
<Header name="Content-Type">application/fhir+json</Header>
</Headers>
<StatusCode>404</StatusCode>
<ReasonPhrase>NotFound</ReasonPhrase>
<Payload>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--
This policy raises a 500 error response for an internal server error.
Raisefault policies stop the execution of the current flow and move to the error flow, which returns the error response defined here to the requesting application.
For more information on RaiseFault policies within Apigee see the following resource:
* https://docs.apigee.com/api-platform/reference/policies/raise-fault-policy
-->
<RaiseFault async="false" continueOnError="false" enabled="true" name="RaiseFault.500InternalServerError">
<DisplayName>RaiseFault.500InternalServerError</DisplayName>
<Properties/>
<FaultResponse>
<Set>
<Headers>
<Header name="Content-Type">application/fhir+json</Header>
</Headers>
<StatusCode>500</StatusCode>
<ReasonPhrase>InternalServerError</ReasonPhrase>
<Payload>
{
"issue": [
{
"code": "invalid",
"details": {
"coding": [
{
"code": "SERVER_ERROR",
"display": "Failed to generate response",
"system": "https://fhir.nhs.uk/R4/CodeSystem/ValidatedRelationships-ErrorOrWarningCode",
"version": "1"
}
]
},
"diagnostics": "Internal Server Error - Failed to generate response",
"severity": "error"
}
],
"resourceType": "OperationOutcome"
}
</Payload>
</Set>
</FaultResponse>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</RaiseFault>
6 changes: 6 additions & 0 deletions proxies/live/apiproxy/targets/target.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
</Condition>
</Step>
</FaultRule>
<FaultRule name="internal_server_error">
<Step>
<Name>RaiseFault.401Unauthorized</Name>
<Condition>fault.status_code = 500</Condition>
</Step>
</FaultRule>
</FaultRules>
<HTTPTargetConnection>
<LoadBalancer>
Expand Down

0 comments on commit ff3a308

Please sign in to comment.