Skip to content

Commit

Permalink
Improve error handling
Browse files Browse the repository at this point in the history
- Sanitize error message in case when response.Content is null
- Handle transport errors gracefully
  • Loading branch information
tymarats committed Aug 21, 2023
1 parent e9b9b4e commit 01243a8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/ConductorSharp.Client/Service/ConductorClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +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);
if (!string.IsNullOrEmpty(response.ErrorMessage))
throw new Exception(response.ErrorMessage);

error = JsonConvert.DeserializeObject<ConductorErrorResponse>(response.Content ?? "{}");

if (error == null || string.IsNullOrEmpty(error.Message))
throw new Exception("Unable to deserialize error");
Expand Down

0 comments on commit 01243a8

Please sign in to comment.