From ea8191210fa2f7ea6a7e5a877b258442f7a6f88b Mon Sep 17 00:00:00 2001 From: Rowan Gill Date: Tue, 18 Apr 2023 09:27:43 +0100 Subject: [PATCH] feature/NRLF-440-apigee-pointer-400 added new error handle for the no pointers --- .../policies/RaiseFault.403NoPointers.xml | 28 +++++++++++++++++++ .../ConnectionMetadata.SetRequestHeaders.js | 4 +-- proxies/live/apiproxy/targets/target.xml | 4 +++ .../policies/RaiseFault.403NoPointers.xml | 28 +++++++++++++++++++ .../ConnectionMetadata.SetRequestHeaders.js | 4 +-- proxies/sandbox/apiproxy/targets/sandbox.xml | 4 +++ 6 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 proxies/live/apiproxy/policies/RaiseFault.403NoPointers.xml create mode 100644 proxies/sandbox/apiproxy/policies/RaiseFault.403NoPointers.xml diff --git a/proxies/live/apiproxy/policies/RaiseFault.403NoPointers.xml b/proxies/live/apiproxy/policies/RaiseFault.403NoPointers.xml new file mode 100644 index 0000000..43b28b8 --- /dev/null +++ b/proxies/live/apiproxy/policies/RaiseFault.403NoPointers.xml @@ -0,0 +1,28 @@ + + + + { + "resourceType": "OperationOutcome", + "issue": [ + { + "severity": "error", + "code": "403", + "details": { + "coding": [ + { + "code": "403", + "display": "Forbidden" + } + ] + }, + "diagnostics": "Provided ODS code has no pointers within requesting app" + } + ] + } + 403 + Forbidden + + + true + RaiseFault.403NoPointers + \ No newline at end of file diff --git a/proxies/live/apiproxy/resources/jsc/ConnectionMetadata.SetRequestHeaders.js b/proxies/live/apiproxy/resources/jsc/ConnectionMetadata.SetRequestHeaders.js index 0681c67..1433319 100644 --- a/proxies/live/apiproxy/resources/jsc/ConnectionMetadata.SetRequestHeaders.js +++ b/proxies/live/apiproxy/resources/jsc/ConnectionMetadata.SetRequestHeaders.js @@ -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-` 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; } diff --git a/proxies/live/apiproxy/targets/target.xml b/proxies/live/apiproxy/targets/target.xml index c3a13d1..9859320 100644 --- a/proxies/live/apiproxy/targets/target.xml +++ b/proxies/live/apiproxy/targets/target.xml @@ -16,6 +16,10 @@ Javascript.AddConnectionMetadataHeader + + request.header.NHSD-Connection-Metadata = null + RaiseFault.403NoPointers + diff --git a/proxies/sandbox/apiproxy/policies/RaiseFault.403NoPointers.xml b/proxies/sandbox/apiproxy/policies/RaiseFault.403NoPointers.xml new file mode 100644 index 0000000..43b28b8 --- /dev/null +++ b/proxies/sandbox/apiproxy/policies/RaiseFault.403NoPointers.xml @@ -0,0 +1,28 @@ + + + + { + "resourceType": "OperationOutcome", + "issue": [ + { + "severity": "error", + "code": "403", + "details": { + "coding": [ + { + "code": "403", + "display": "Forbidden" + } + ] + }, + "diagnostics": "Provided ODS code has no pointers within requesting app" + } + ] + } + 403 + Forbidden + + + true + RaiseFault.403NoPointers + \ No newline at end of file diff --git a/proxies/sandbox/apiproxy/resources/jsc/ConnectionMetadata.SetRequestHeaders.js b/proxies/sandbox/apiproxy/resources/jsc/ConnectionMetadata.SetRequestHeaders.js index e4d8843..83eeef8 100644 --- a/proxies/sandbox/apiproxy/resources/jsc/ConnectionMetadata.SetRequestHeaders.js +++ b/proxies/sandbox/apiproxy/resources/jsc/ConnectionMetadata.SetRequestHeaders.js @@ -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; } diff --git a/proxies/sandbox/apiproxy/targets/sandbox.xml b/proxies/sandbox/apiproxy/targets/sandbox.xml index 0c339fe..2b2920e 100644 --- a/proxies/sandbox/apiproxy/targets/sandbox.xml +++ b/proxies/sandbox/apiproxy/targets/sandbox.xml @@ -26,6 +26,10 @@ Javascript.AddConnectionMetadataHeader + + request.header.NHSD-Connection-Metadata = null + RaiseFault.403NoPointers +