From ab5112f1b4cbe114b64cdb08f8a2500d5f396b56 Mon Sep 17 00:00:00 2001 From: Robert Baillie Date: Thu, 7 Apr 2022 15:14:58 +0100 Subject: [PATCH] Added the ability to strip context from ortoo_Exceptions --- .../classes/exceptions/ortoo_Exception.cls | 12 ++++++++++++ .../exceptions/tests/ortoo_ExceptionTest.cls | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/framework/default/ortoo-core/default/classes/exceptions/ortoo_Exception.cls b/framework/default/ortoo-core/default/classes/exceptions/ortoo_Exception.cls index 690c0ea88a4..3adea5ea33c 100644 --- a/framework/default/ortoo-core/default/classes/exceptions/ortoo_Exception.cls +++ b/framework/default/ortoo-core/default/classes/exceptions/ortoo_Exception.cls @@ -127,6 +127,18 @@ public virtual class ortoo_Exception extends Exception implements IRenderableMes return contexts; } + /** + * Removes the context from the current exception, ensuring that no + * sensitive information remains in it. + * + * @return ortoo_Exception Itself, allowing for a fluent interface + */ + public ortoo_Exception stripContexts() + { + contexts = new Contexts(); + return this; + } + /** * Sets the message details for this exception (e.g. validation errors) * diff --git a/framework/default/ortoo-core/default/classes/exceptions/tests/ortoo_ExceptionTest.cls b/framework/default/ortoo-core/default/classes/exceptions/tests/ortoo_ExceptionTest.cls index aca703d3b52..71adcbce956 100644 --- a/framework/default/ortoo-core/default/classes/exceptions/tests/ortoo_ExceptionTest.cls +++ b/framework/default/ortoo-core/default/classes/exceptions/tests/ortoo_ExceptionTest.cls @@ -186,6 +186,22 @@ public with sharing class ortoo_ExceptionTest { System.assertEquals( getClassName(), contextRecordPoint.getClassName(), 'addContext, when called, will add it to the exception, setting the record point to the class that called addContext' ); } + @isTest + private static void stripContexts_whenCalled_willRemoveAllContextInfo() // NOPMD: Test method name format + { + ortoo_Exception e = new ortoo_Exception( 'message' ) + .addContext( 'ParameterName1', 'ParameterValue1' ) + .addContext( 'ParameterName2', 'ParameterValue2' ); + + Test.startTest(); + e.stripContexts(); + Test.stopTest(); + + ortoo_Exception.Contexts contexts = e.getContexts(); + + System.assertEquals( 0, contexts.size(), 'stripContexts, when called, will remove all contexts' ); + } + @isTest private static void addContext_whenCalledInInnerClass_willAddIncludeInStack() // NOPMD: Test method name format {