Skip to content

Commit

Permalink
When an Exception is thrown during a Watch operation, call `OnErr…
Browse files Browse the repository at this point in the history
…or` on the observable instead of throwing `NotImplementedException`
  • Loading branch information
jordansjones committed Sep 19, 2016
1 parent 1a4d858 commit 8711475
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
3 changes: 3 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### New in 1.0.4 (Release 2016/09/19)
* Fixed: When an `Exception` is thrown during a `Watch` operation, call `OnError` on the observable instead of throwing `NotImplementedException`

### New in 1.0.3 (Release 2016/08/24)
* Fixed: All Exceptions are now `[Serializable]`

Expand Down
34 changes: 13 additions & 21 deletions source/Draft/Exceptions/ExceptionHandling.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Sockets;
Expand All @@ -26,29 +25,22 @@ internal static class ExceptionHandling

#endregion

public static EtcdException ProcessException(this Exception This)
public static EtcdException ProcessException(this FlurlHttpException This)
{
var fhe = This as FlurlHttpException;
if (fhe == null)
{
Debugger.Break();
throw new NotImplementedException();
}


if (fhe.IsTimeoutException()) { return fhe.AsTimeoutException(); }
if (fhe.IsInvalidHostException()) { return fhe.AsInvalidHostException(); }
if (fhe.IsInvalidRequestException()) { return fhe.AsInvalidRequestException(); }
if (fhe.IsBadRequestException()) { return fhe.AsBadRequestException(); }
if (fhe.IsServiceUnavailableException()) { return fhe.AsServiceUnavailableException(); }
if (fhe.IsHttpConnectionException()) { return fhe.AsHttpConnectionException(); }
if (This.IsTimeoutException()) { return This.AsTimeoutException(); }
if (This.IsInvalidHostException()) { return This.AsInvalidHostException(); }
if (This.IsInvalidRequestException()) { return This.AsInvalidRequestException(); }
if (This.IsBadRequestException()) { return This.AsBadRequestException(); }
if (This.IsServiceUnavailableException()) { return This.AsServiceUnavailableException(); }
if (This.IsHttpConnectionException()) { return This.AsHttpConnectionException(); }

var etcdError = fhe.GetResponseJson<EtcdError>();
var etcdError = This.GetResponseJson<EtcdError>();

var message = etcdError.Message;

etcdError.ErrorCode = etcdError.ErrorCode
?? (fhe.GetEtcdErrorCode() ?? EtcdErrorCode.Unknown);
?? (This.GetEtcdErrorCode() ?? EtcdErrorCode.Unknown);

EtcdException exception;
// Ugh. The switch from hell.
Expand Down Expand Up @@ -147,11 +139,11 @@ public static EtcdException ProcessException(this Exception This)
}

exception.EtcdError = etcdError;
if (fhe.Call != null)
if (This.Call != null)
{
exception.HttpStatusCode = fhe.Call.HttpStatus;
exception.RequestUrl = fhe.Call.Request.RequestUri.ToString();
exception.RequestMethod = fhe.Call.Request.Method;
exception.HttpStatusCode = This.Call.HttpStatus;
exception.RequestUrl = This.Call.Request.RequestUri.ToString();
exception.RequestMethod = This.Call.Request.Method;
}

return exception;
Expand Down
2 changes: 1 addition & 1 deletion source/Draft/Requests/WatchRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private async Task StartPollingAsync(IObserver<IKeyEvent> observer, Cancellation
}
catch (Exception e)
{
observer.OnError(e.ProcessException());
observer.OnError(e);
break;
}
}
Expand Down

0 comments on commit 8711475

Please sign in to comment.