This commit is contained in:
Todd 2020-12-13 17:38:16 -06:00
parent edcf60a62c
commit 9979491571
2 changed files with 13 additions and 4 deletions

View File

@ -55,5 +55,11 @@ namespace Flurl.Test.Http
Assert.IsInstanceOf<Newtonsoft.Json.JsonReaderException>(ex.InnerException); Assert.IsInstanceOf<Newtonsoft.Json.JsonReaderException>(ex.InnerException);
} }
} }
[Test] // #579
public void can_create_empty() {
var ex = new FlurlHttpException(null);
Assert.AreEqual("Call failed.", ex.Message);
}
} }
} }

View File

@ -40,10 +40,13 @@ namespace Flurl.Http
public FlurlHttpException(FlurlCall call) : this(call, BuildMessage(call, null), null) { } public FlurlHttpException(FlurlCall call) : this(call, BuildMessage(call, null), null) { }
private static string BuildMessage(FlurlCall call, Exception inner) { private static string BuildMessage(FlurlCall call, Exception inner) {
return if (call?.Response != null && !call.Succeeded)
(call.Response != null && !call.Succeeded) ? return $"Call failed with status code {call.Response.StatusCode} ({call.HttpResponseMessage.ReasonPhrase}): {call}";
$"Call failed with status code {call.Response.StatusCode} ({call.HttpResponseMessage.ReasonPhrase}): {call}":
$"Call failed. {inner?.Message} {call}"; var msg = "Call failed.";
if (inner != null) msg += " " + inner.Message;
if (call != null) msg += " " + call;
return msg;
} }
/// <summary> /// <summary>