refit icon indicating copy to clipboard operation
refit copied to clipboard

[Bug]: Not throwing a ValidationApiException

Open goforebroke opened this issue 1 year ago • 2 comments
trafficstars

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

goforebroke avatar May 21 '24 22:05 goforebroke

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

IsaacHayes1995 avatar Jun 25 '24 06:06 IsaacHayes1995

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);
}

TimothyMakkison avatar Nov 11 '24 18:11 TimothyMakkison