Skip to content

Commit

Permalink
#579 better null handling in exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
tmenier committed Dec 14, 2020
1 parent 18cf6b4 commit 598e88e
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/Flurl.Http/FlurlHttpException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ private static string BuildMessage(FlurlCall call, Exception inner) {
if (call?.Response != null && !call.Succeeded)
return $"Call failed with status code {call.Response.StatusCode} ({call.HttpResponseMessage.ReasonPhrase}): {call}";

var msg = "Call failed.";
if (inner != null) msg += " " + inner.Message;
if (call != null) msg += " " + call;
return msg;
var msg = "Call failed";
if (inner != null) msg += ". " + inner.Message.TrimEnd('.');
return msg + ((call == null) ? "." : $": {call}");
}

/// <summary>
Expand Down Expand Up @@ -82,9 +81,8 @@ public class FlurlHttpTimeoutException : FlurlHttpException
/// <param name="inner">The inner exception.</param>
public FlurlHttpTimeoutException(FlurlCall call, Exception inner) : base(call, BuildMessage(call), inner) { }

private static string BuildMessage(FlurlCall call) {
return $"Call timed out: {call}";
}
private static string BuildMessage(FlurlCall call) =>
(call == null) ? "Call timed out." : $"Call timed out: {call}";
}

/// <summary>
Expand All @@ -108,8 +106,8 @@ public FlurlParsingException(FlurlCall call, string expectedFormat, Exception in
public string ExpectedFormat { get; }

private static string BuildMessage(FlurlCall call, string expectedFormat) {
return $"Response could not be deserialized to {expectedFormat}: {call}";
var msg = $"Response could not be deserialized to {expectedFormat}";
return msg + ((call == null) ? "." : $": {call}");
}
}

}

0 comments on commit 598e88e

Please sign in to comment.