Skip to content

Commit

Permalink
Improve error handling (#147)
Browse files Browse the repository at this point in the history
* Improve error handling

- Sanitize error message in case when response.Content is null
- Handle transport errors gracefully

* DeserializeObject: Clarify intent

* Prefer custom error over the generic one

...in case they're both set.
  • Loading branch information
tymarats authored Aug 29, 2023
1 parent e9b9b4e commit 9769e4d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ConductorSharp.Client/Service/ConductorClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ private void CheckResponse(RestResponse response)

_logger.LogInformation("Received {@Response} with status code {@StatusCode}", response.Content, (int)response.StatusCode);

error = JsonConvert.DeserializeObject<ConductorErrorResponse>(response.Content);
error = response.Content != null ? JsonConvert.DeserializeObject<ConductorErrorResponse>(response.Content) : null;

if (error == null || string.IsNullOrEmpty(error.Message))
throw new Exception("Unable to deserialize error");
throw new Exception(response.ErrorMessage ?? "Unable to deserialize error");

_logger.LogError("{@conductorError}", error);

Expand Down

0 comments on commit 9769e4d

Please sign in to comment.