Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Not throwing a ValidationApiException #1702

Open
goforebroke opened this issue May 21, 2024 · 2 comments
Open

[Bug]: Not throwing a ValidationApiException #1702

goforebroke opened this issue May 21, 2024 · 2 comments
Labels

Comments

@goforebroke
Copy link

goforebroke commented May 21, 2024

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 goforebroke changed the title [Bug]: Not able to throw Validation Exception [Bug]: Not able to throw ValidationApiException May 22, 2024
@goforebroke goforebroke changed the title [Bug]: Not able to throw ValidationApiException [Bug]: Not throwing a ValidationApiException May 22, 2024
@IsaacHayes1995
Copy link

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

@TimothyMakkison
Copy link
Contributor

TimothyMakkison commented Nov 11, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants