From 87114752bcc816d79755ca1f7ddfe5c3a8a17ee2 Mon Sep 17 00:00:00 2001 From: "Jordan S. Jones" Date: Mon, 19 Sep 2016 14:08:17 -0600 Subject: [PATCH] When an `Exception` is thrown during a `Watch` operation, call `OnError` on the observable instead of throwing `NotImplementedException` --- ReleaseNotes.md | 3 ++ source/Draft/Exceptions/ExceptionHandling.cs | 34 ++++++++------------ source/Draft/Requests/WatchRequest.cs | 2 +- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/ReleaseNotes.md b/ReleaseNotes.md index 7259d1f..8fca4cf 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -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]` diff --git a/source/Draft/Exceptions/ExceptionHandling.cs b/source/Draft/Exceptions/ExceptionHandling.cs index a87142d..707418b 100644 --- a/source/Draft/Exceptions/ExceptionHandling.cs +++ b/source/Draft/Exceptions/ExceptionHandling.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics; using System.Linq; using System.Net; using System.Net.Sockets; @@ -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(); + var etcdError = This.GetResponseJson(); var message = etcdError.Message; etcdError.ErrorCode = etcdError.ErrorCode - ?? (fhe.GetEtcdErrorCode() ?? EtcdErrorCode.Unknown); + ?? (This.GetEtcdErrorCode() ?? EtcdErrorCode.Unknown); EtcdException exception; // Ugh. The switch from hell. @@ -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; diff --git a/source/Draft/Requests/WatchRequest.cs b/source/Draft/Requests/WatchRequest.cs index a6a6259..8bd052c 100644 --- a/source/Draft/Requests/WatchRequest.cs +++ b/source/Draft/Requests/WatchRequest.cs @@ -114,7 +114,7 @@ private async Task StartPollingAsync(IObserver observer, Cancellation } catch (Exception e) { - observer.OnError(e.ProcessException()); + observer.OnError(e); break; } }