Skip to content

Instantly share code, notes, and snippets.

@jkonecki
Created October 10, 2014 09:30
Show Gist options
  • Save jkonecki/fc8df37e5642584a8c99 to your computer and use it in GitHub Desktop.
Save jkonecki/fc8df37e5642584a8c99 to your computer and use it in GitHub Desktop.
Transient error detection strategy for RavenDB using Microsoft.Practices.TransientFaultHandling application block
using Microsoft.Practices.TransientFaultHandling;
public class RavenDBTransientErrorDetectionStrategy : ITransientErrorDetectionStrategy
{
public bool IsTransient(Exception ex)
{
dynamic currentException = ex;
while(currentException != null)
{
if (this.IsExceptionTransient(currentException))
return true;
currentException = currentException.InnerException;
}
return false;
}
private bool IsExceptionTransient(Exception ex)
{
return false;
}
private bool IsExceptionTransient(TimeoutException ex)
{
return true;
}
private bool IsExceptionTransient(WebException ex)
{
var transientStatuses = new HashSet<WebExceptionStatus>(new []
{
WebExceptionStatus.ConnectFailure,
WebExceptionStatus.ConnectionClosed,
WebExceptionStatus.KeepAliveFailure,
WebExceptionStatus.Pending,
WebExceptionStatus.PipelineFailure,
WebExceptionStatus.ProtocolError,
WebExceptionStatus.ReceiveFailure,
WebExceptionStatus.RequestCanceled,
WebExceptionStatus.SecureChannelFailure,
WebExceptionStatus.SendFailure,
WebExceptionStatus.Timeout
});
return transientStatuses.Contains(ex.Status);
}
}
@hyrmn
Copy link

hyrmn commented May 5, 2015

What's been your impl strategy? Wrap every call to session.SaveChanges() or subclass DocumentSession and internally wrap the call or something completely different?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment