-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #278 from Simon-Campbell/expose-default-fault-tran…
…sformer Make a default FaultExceptionTransformer
- Loading branch information
Showing
4 changed files
with
41 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.ServiceModel.Channels; | ||
|
||
namespace SoapCore | ||
{ | ||
/// <summary> | ||
/// The default implementation of the fault provider when an unexpected exception occurs. This can be replaced or | ||
/// extended by registering your own IFaultExceptionTransformer in the service collection on startup. | ||
/// </summary> | ||
public class DefaultFaultExceptionTransformer : IFaultExceptionTransformer | ||
{ | ||
private readonly ExceptionTransformer _exceptionTransformer; | ||
|
||
public DefaultFaultExceptionTransformer() | ||
{ | ||
_exceptionTransformer = null; | ||
} | ||
|
||
public DefaultFaultExceptionTransformer(ExceptionTransformer exceptionTransformer) | ||
{ | ||
_exceptionTransformer = exceptionTransformer; | ||
} | ||
|
||
public Message ProvideFault(Exception exception, MessageVersion messageVersion) | ||
{ | ||
var bodyWriter = _exceptionTransformer == null ? | ||
new FaultBodyWriter(exception, messageVersion) : | ||
new FaultBodyWriter(exception, messageVersion, faultStringOverride: _exceptionTransformer.Transform(exception)); | ||
|
||
var soapCoreFaultMessage = Message.CreateMessage(messageVersion, null, bodyWriter); | ||
|
||
return new CustomMessage(soapCoreFaultMessage); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters