reactiveui/refit

[Bug]: Not throwing a ValidationApiException

goforebroke opened this issue ยท 2 comments

Describe the bug ๐Ÿž

A bug happened!

I have an API that returns a problem details when supplied inputs fail validation

refit 1 refit 2

I have a razor page application using the refit library to make api calls.

refit 5

When the application posts data with invalid inputs an ApiException is caught, but not a ValidationApiException. If the ApiException has a content type "application/problem+json", a ValidationApiException should be thrown?

refit 4 refit 3

Step to reproduce

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Reproduction repository

https://github.com/reactiveui/refit

Expected behavior

This should happen...

A ValidationException should be thrown with a content type application/problem+json

Screenshots ๐Ÿ–ผ๏ธ

No response

IDE

Visual Studio 2022

Operating system

Windows

Version

11

Device

No response

Refit Version

Refit.HttpClientFactory 7.0.0

Additional information โ„น๏ธ

No response

Bumping this, as I've just hit the same issue.

Hey, could you share a minimal reproduction of this issue? I haven't been able to reproduce in a modern ASP project.

I'm guessing your issue is related to this line in ApiException, I'm guessing the returned header in your example is being recognized by Refit.

if (
    response
        .Content.Headers?.ContentType
        ?.MediaType
        ?.Equals("application/problem+json") ?? false
)
{
    exception = ValidationApiException.Create(exception);
}