Skip to content

Commit

Permalink
Merge pull request #67 from NHSDigital/feature/NRLF-440-apigee-pointe…
Browse files Browse the repository at this point in the history
…r-400

feature/NRLF-440-apigee-pointer-400 added changes to error handling f…
  • Loading branch information
Rohoolio authored Apr 18, 2023
2 parents 281954a + ea81912 commit 4cb7936
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 4 deletions.
28 changes: 28 additions & 0 deletions proxies/live/apiproxy/policies/RaiseFault.403NoPointers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<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>
<StatusCode>403</StatusCode>
<ReasonPhrase>Forbidden</ReasonPhrase>
</Set>
</FaultResponse>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<DisplayName>RaiseFault.403NoPointers</DisplayName>
</RaiseFault>
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
// Read the 'NHSD-End-User-Organisation-ODS' header
var odsCode = context.getVariable('request.header.NHSD-End-User-Organisation-ODS');
if (!odsCode || odsCode.trim().length === 0) {
context.setVariable("badRequest", true);
//This will trigger RaiseFault.400BadRequest.xml - see proxies/deafult.xml in the DefaultFaultRules
return;
}

// Read the associated `nrl-ods-<ods_code>` custom attribute from the APIGEE app
var nrlPointerTypes = context.getVariable('app.nrl-ods-' + odsCode);
if (!nrlPointerTypes) {
context.setVariable("badRequest", true);
//This will trigger RaiseFault.403NoPointers.xml - see targets/target.xml
return;
}

Expand Down
4 changes: 4 additions & 0 deletions proxies/live/apiproxy/targets/target.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<Step>
<Name>Javascript.AddConnectionMetadataHeader</Name>
</Step>
<Step>
<Condition>request.header.NHSD-Connection-Metadata = null</Condition>
<Name>RaiseFault.403NoPointers</Name>
</Step>
</Request>
</PreFlow>
<FaultRules>
Expand Down
28 changes: 28 additions & 0 deletions proxies/sandbox/apiproxy/policies/RaiseFault.403NoPointers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<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>
<StatusCode>403</StatusCode>
<ReasonPhrase>Forbidden</ReasonPhrase>
</Set>
</FaultResponse>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<DisplayName>RaiseFault.403NoPointers</DisplayName>
</RaiseFault>
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ const nrlPointers = {
"request.header.NHSD-End-User-Organisation-ODS"
);
if (!odsCode || odsCode.trim().length === 0) {
context.setVariable("badRequest", true);
//This will trigger RaiseFault.400BadRequest.xml - see proxies/deafult.xml in the DefaultFaultRules
return;
}

var nrlPointerTypes = nrlPointers[odsCode];
if (!nrlPointerTypes) {
context.setVariable("badRequest", true);
//This will trigger RaiseFault.400NoPointers.xml - see targets/target.xml
return;
}

Expand Down
4 changes: 4 additions & 0 deletions proxies/sandbox/apiproxy/targets/sandbox.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
<Step>
<Name>Javascript.AddConnectionMetadataHeader</Name>
</Step>
<Step>
<Condition>request.header.NHSD-Connection-Metadata = null</Condition>
<Name>RaiseFault.403NoPointers</Name>
</Step>
</Request>
<!-- <Response>
<Step>
Expand Down

0 comments on commit 4cb7936

Please sign in to comment.