Skip to content

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

@robfe

Description

@robfe

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions