merge-api / merge-csharp-client

The C Sharp SDK for accessing various Merge Unified APIs
Other
2 stars 1 forks source link

Base class Exception could be more specific (`throw new Exception(responseBody)`) #27

Closed robfe closed 1 month ago

robfe commented 4 months ago

I don't think the following code is very helpful for real error handling scenarios:

string responseBody = await response.Raw.Content.ReadAsStringAsync();
if (response.StatusCode >= 200 && response.StatusCode < 400)
{
    return JsonSerializer.Deserialize<PaginatedScreeningQuestionList>(responseBody);
}
throw new Exception(responseBody);

It's impossible to tell what caused the exception when Exception is already the base class for all exceptions. Also, the status code is no longer available for inspection

Actually, I've just spotted in your docs that there is already an improvement in the works, very aligned with what I was hoping for: https://github.com/merge-api/merge-csharp-client?tab=readme-ov-file#exception-handling

When will that documentation become true?

dsinghvi commented 1 month ago

@robfe this is now supported as well (https://github.com/merge-api/merge-csharp-client/blob/a35417c8ea2d6f68f8bfc76b271eb8e4ab30094e/src/Merge.Client/Crm/AssociationTypes/AssociationTypesClient.cs#L95-L111)