Skip to content

Commit

Permalink
Added the ability to strip context from ortoo_Exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-baillie-ortoo committed Apr 7, 2022
1 parent 6238a10 commit ab5112f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit ab5112f

Please sign in to comment.