Skip to content

Commit

Permalink
[NRL-602] Make apigee error responses into valid OperationOutcomes
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdean3-nhs committed Apr 19, 2024
1 parent c10c128 commit 4968ed2
Show file tree
Hide file tree
Showing 15 changed files with 146 additions and 88 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="AssignMessage.Errors.CatchAllMessage">
<Set>
<Payload contentType="application/json" variablePrefix="%" variableSuffix="#">
<Payload contentType="application/json">
{
"resourceType": "OperationOutcome",
"issue": [
{
"issue": [ {
"severity": "error",
"code": "%error.status.code#",
"code": "exception",
"details": {
"coding": [
{
"code": "%error.status.code#",
"display": "%error.reason.phrase#"
"system": "https://fhir.nhs.uk/spine-error-or-warning-code-1",
"code": "ACCESS DENIED"
"display": "Access has been denied to process this request"
}
]
},
"diagnostics": "%error.content#"
}
]
"diagnostics": "{error.content}"
} ]
}
</Payload>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
"details": {
"coding": [
{
"system": "https://fhir.nhs.uk/R4/CodeSystem/Spine-ErrorOrWarningCode",
"version": "1",
"system": "https://fhir.nhs.uk/spine-error-or-warning-code-1",
"code": "ACCESS_DENIED",
"display": "{faultstring}"
"display": "Access has been denied to process this request"
}
]
}
},
"disagnostics": "{faultstring}"
}
]
}
Expand Down
10 changes: 0 additions & 10 deletions proxies/live/apiproxy/policies/RaiseFault.400BadRequest.xml

This file was deleted.

26 changes: 26 additions & 0 deletions proxies/live/apiproxy/policies/RaiseFault.400MissingODSHeader.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<RaiseFault async="false" continueOnError="false" enabled="true" name="RaiseFault.400MissingODSHeader">
<FaultResponse>
<Set>
<Payload contentType="text/plain">
{
"resourceType": "OperationOutcome",
"issue": [ {
"severity": "error",
"code": "required",
"details": {
"coding": [ {
"system": "https://fhir.nhs.uk/spine-error-or-warning-code-1",
"code": "MISSING_OR_INVALID_HEADER",
"display": "There is a required header missing or invalid"
} ]
},
"diagnostics": "The NHSD-End-User-Organisation-ODS header is missing or invalid"
} ]
}
</Payload>
<StatusCode>400</StatusCode>
<ReasonPhrase>Bad Request</ReasonPhrase>
</Set>
</FaultResponse>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</RaiseFault>
18 changes: 17 additions & 1 deletion proxies/live/apiproxy/policies/RaiseFault.401Unauthorized.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,23 @@
<FaultResponse>
<Set>
<Headers/>
<Payload contentType="text/plain"/>
<Payload contentType="text/plain">
{
"resourceType": "OperationOutcome",
"issue": [ {
"severity": "error",
"code": "forbidden",
"details": {
"coding": [ {
"system": "https://fhir.nhs.uk/spine-error-or-warning-code-1",
"code": "ACCESS_DENIED",
"display": "Access has been denied to process this request"
} ]
},
"diagnostics": "You are not authorized to access this resource."
} ]
}
</Payload>
<StatusCode>401</StatusCode>
<ReasonPhrase>Access Denied</ReasonPhrase>
</Set>
Expand Down
35 changes: 17 additions & 18 deletions proxies/live/apiproxy/policies/RaiseFault.403NoPointers.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
<RaiseFault async="false" continueOnError="false" enabled="true" name="RaiseFault.403NoPointers">
<FaultResponse>
<Set>
<Payload contentType="application/json"> {
"resourceType": "OperationOutcome",
"issue": [
{
"severity": "error",
"code": "403",
"details": {
"coding": [
{
"code": "403",
"display": "Forbidden"
}
]
},
"diagnostics": "Provided ODS code has no pointers within requesting app"
}
]
}</Payload>
<Payload contentType="application/json">
{
"resourceType": "OperationOutcome",
"issue": [ {
"severity": "error",
"code": "forbidden",
"details": {
"coding": [ {
"system": "https://fhir.nhs.uk/spine-error-or-warning-code-1",
"code": "ACCESS_DENIED",
"display": "Access has been denied to process this request"
} ]
},
"diagnostics": "Provided ODS code has no pointers within requesting app"
} ]
}
</Payload>
<StatusCode>403</StatusCode>
<ReasonPhrase>Forbidden</ReasonPhrase>
</Set>
Expand Down
5 changes: 2 additions & 3 deletions proxies/live/apiproxy/proxies/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
<Flow name="Raise400ForMissingODSHeader">
<Request>
<Step>
<Name>RaiseFault.400BadRequest</Name>
<Message>Missing Header: NHSD-End-User-Organisation-ODS</Message>
<Name>RaiseFault.400MissingODSHeader</Name>
</Step>
</Request>
<Condition>request.verb != "OPTIONS" and (request.header.NHSD-End-User-Organisation-ODS = null or request.header.NHSD-End-User-Organisation-ODS = "")</Condition>
Expand Down Expand Up @@ -77,7 +76,7 @@
</Step>
<Step>
<Name>AssignMessage.Errors.CatchAllMessage</Name>
<Condition>(response.content NOT Like "*OperationOutcome*")</Condition>
<Condition>(response.content NOT Like "*OperationOutcome*") and (error.content NOT Like "*OperationOutcome*")</Condition>
</Step>
</DefaultFaultRule>
</ProxyEndpoint>
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"request.header.NHSD-End-User-Organisation-ODS"
);
if (!odsCode || odsCode.trim().length === 0) {
//This will trigger RaiseFault.400BadRequest.xml - see proxies/deafult.xml in the DefaultFaultRules
//This will trigger RaiseFault.400MissingODSHeader.xml - see proxies/deafult.xml in the DefaultFaultRules
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="AssignMessage.Errors.CatchAllMessage">
<Set>
<Payload contentType="application/json" variablePrefix="%" variableSuffix="#">
<Payload contentType="application/json">
{
"resourceType": "OperationOutcome",
"issue": [
{
"issue": [ {
"severity": "error",
"code": "%error.status.code#",
"code": "exception",
"details": {
"coding": [
{
"code": "%error.status.code#",
"display": "%error.reason.phrase#"
"system": "https://fhir.nhs.uk/spine-error-or-warning-code-1",
"code": "ACCESS DENIED"
"display": "Access has been denied to process this request"
}
]
},
"diagnostics": "%error.content#"
}
]
"diagnostics": "{error.content}"
} ]
}
</Payload>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
Expand Down
10 changes: 0 additions & 10 deletions proxies/sandbox/apiproxy/policies/RaiseFault.400BadRequest.xml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<RaiseFault async="false" continueOnError="false" enabled="true" name="RaiseFault.400MissingODSHeader">
<FaultResponse>
<Set>
<Payload contentType="text/plain">
{
"resourceType": "OperationOutcome",
"issue": [ {
"severity": "error",
"code": "required",
"details": {
"coding": [ {
"system": "https://fhir.nhs.uk/spine-error-or-warning-code-1",
"code": "MISSING_OR_INVALID_HEADER",
"display": "There is a required header missing or invalid"
} ]
},
"diagnostics": "The NHSD-End-User-Organisation-ODS header is missing or invalid"
} ]
}
</Payload>
<StatusCode>400</StatusCode>
<ReasonPhrase>Bad Request</ReasonPhrase>
</Set>
</FaultResponse>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</RaiseFault>
18 changes: 17 additions & 1 deletion proxies/sandbox/apiproxy/policies/RaiseFault.401Unauthorized.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,23 @@
<FaultResponse>
<Set>
<Headers/>
<Payload contentType="text/plain"/>
<Payload contentType="text/plain">
{
"resourceType": "OperationOutcome",
"issue": [ {
"severity": "error",
"code": "forbidden",
"details": {
"coding": [ {
"system": "https://fhir.nhs.uk/spine-error-or-warning-code-1",
"code": "ACCESS_DENIED",
"display": "Access has been denied to process this request"
} ]
},
"diagnostics": "You are not authorized to access this resource."
} ]
}
</Payload>
<StatusCode>401</StatusCode>
<ReasonPhrase>Access Denied</ReasonPhrase>
</Set>
Expand Down
35 changes: 17 additions & 18 deletions proxies/sandbox/apiproxy/policies/RaiseFault.403NoPointers.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
<RaiseFault async="false" continueOnError="false" enabled="true" name="RaiseFault.403NoPointers">
<FaultResponse>
<Set>
<Payload contentType="application/json"> {
"resourceType": "OperationOutcome",
"issue": [
{
"severity": "error",
"code": "403",
"details": {
"coding": [
{
"code": "403",
"display": "Forbidden"
}
]
},
"diagnostics": "Provided ODS code has no pointers within requesting app"
}
]
}</Payload>
<Payload contentType="application/json">
{
"resourceType": "OperationOutcome",
"issue": [ {
"severity": "error",
"code": "forbidden",
"details": {
"coding": [ {
"system": "https://fhir.nhs.uk/spine-error-or-warning-code-1",
"code": "ACCESS_DENIED",
"display": "Access has been denied to process this request"
} ]
},
"diagnostics": "Provided ODS code has no pointers within requesting app"
} ]
}
</Payload>
<StatusCode>403</StatusCode>
<ReasonPhrase>Forbidden</ReasonPhrase>
</Set>
Expand Down
5 changes: 2 additions & 3 deletions proxies/sandbox/apiproxy/proxies/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
<Flow name="Raise400ForMissingODSHeader">
<Request>
<Step>
<Name>RaiseFault.400BadRequest</Name>
<Message>Missing Header: NHSD-End-User-Organisation-ODS</Message>
<Name>RaiseFault.400MissingODSHeader</Name>
</Step>
</Request>
<Condition>request.verb != "OPTIONS" and (request.header.NHSD-End-User-Organisation-ODS = null or request.header.NHSD-End-User-Organisation-ODS = "")</Condition>
Expand Down Expand Up @@ -78,7 +77,7 @@
</Step>
<Step>
<Name>AssignMessage.Errors.CatchAllMessage</Name>
<Condition>(response.content NOT Like "*OperationOutcome*")</Condition>
<Condition>(response.content NOT Like "*OperationOutcome*") and (error.content NOT Like "*OperationOutcome*")</Condition>
</Step>
</DefaultFaultRule>
</ProxyEndpoint>
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const permissions = [];
"request.header.NHSD-End-User-Organisation-ODS"
);
if (!odsCode || odsCode.trim().length === 0) {
//This will trigger RaiseFault.400BadRequest.xml - see proxies/deafult.xml in the DefaultFaultRules
//This will trigger RaiseFault.400MissingODSHeader.xml - see proxies/deafult.xml in the DefaultFaultRules
return;
}

Expand Down

0 comments on commit 4968ed2

Please sign in to comment.