From 47f63677df801cfeb6e7e215191ce3e042803511 Mon Sep 17 00:00:00 2001 From: Todd Menier Date: Fri, 1 Sep 2017 18:17:20 -0500 Subject: [PATCH] Added verb to error messages, so we have "POST http://... failed" instead of "Request to http://... failed" --- src/Flurl.Http/FlurlHttpException.cs | 18 +++++++----------- src/Flurl.Http/HttpCall.cs | 8 ++++++++ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Flurl.Http/FlurlHttpException.cs b/src/Flurl.Http/FlurlHttpException.cs index ccc67a9..30e0272 100644 --- a/src/Flurl.Http/FlurlHttpException.cs +++ b/src/Flurl.Http/FlurlHttpException.cs @@ -38,18 +38,14 @@ namespace Flurl.Http public FlurlHttpException(HttpCall call) : this(call, BuildMessage(call, null), null) { } private static string BuildMessage(HttpCall call, Exception inner) { - if (call.Response != null && !call.Succeeded) { - return string.Format("Request to {0} failed with status code {1} ({2}).", - call.Request.RequestUri.AbsoluteUri, - (int)call.Response.StatusCode, - call.Response.ReasonPhrase); - } - if (inner != null) { - return $"Request to {call.Request.RequestUri.AbsoluteUri} failed. {inner.Message}"; - } + if (call.Response != null && !call.Succeeded) + return $"{call} failed with status code {(int)call.Response.StatusCode} ({call.Response.ReasonPhrase})."; + + if (inner != null) + return $"{call} failed. {inner.Message}"; // in theory we should never get here. - return $"Request to {call.Request.RequestUri.AbsoluteUri} failed."; + return $"{call} failed."; } /// @@ -93,7 +89,7 @@ namespace Flurl.Http public FlurlHttpTimeoutException(HttpCall call, Exception inner) : base(call, BuildMessage(call), inner) { } private static string BuildMessage(HttpCall call) { - return $"Request to {call} timed out."; + return $"{call} timed out."; } } } \ No newline at end of file diff --git a/src/Flurl.Http/HttpCall.cs b/src/Flurl.Http/HttpCall.cs index 39c0141..261c303 100644 --- a/src/Flurl.Http/HttpCall.cs +++ b/src/Flurl.Http/HttpCall.cs @@ -108,5 +108,13 @@ namespace Flurl.Http /// Body of the HTTP response if unsuccessful, otherwise null. (Successful responses are not captured as strings, mainly for performance reasons.) /// public string ErrorResponseBody { get; set; } + + /// + /// Returns the verb and absolute URI associated with this call. + /// + /// + public override string ToString() { + return $"{Request.Method:U} {Request.RequestUri.AbsoluteUri}"; + } } }