You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When a validation of a api request body fails the thrown exception doesn't give any details on what exactly failed.
To Reproduce
Steps to reproduce the behavior:
Make a call to any endpoint with a validation added to it but make sure it fails
See error
Here the failures has 1 item: {Email is required and must be valid.}
The response i get is the following:
HDN_Component_App.Application.Common.Exceptions.ValidationException: One or more validation failures have occurred.
at HDN_Component_App.Application.Common.Behaviours.ValidationBehaviour2.Handle(TRequest request, RequestHandlerDelegate1 next, CancellationToken cancellationToken)
at HDN_Component_App.Application.Common.Behaviours.AuthorizationBehaviour2.Handle(TRequest request, RequestHandlerDelegate1 next, CancellationToken cancellationToken)
at HDN_Component_App.Application.Common.Behaviours.UnhandledExceptionBehaviour2.Handle(TRequest request, RequestHandlerDelegate1 next, CancellationToken cancellationToken)
at HDN_Component_App.Web.Endpoints.Users.CreateUser(ISender sender, CreateUserCommand command) in D:\Projects\HDN-Component-App\Back-End\src\Web\Endpoints\Users.cs:line 34
at Microsoft.AspNetCore.Http.RequestDelegateFactory.g__ExecuteAwaited|121_0(Task`1 task, HttpContext httpContext)
at Microsoft.AspNetCore.Http.RequestDelegateFactory.<>c__DisplayClass94_2.<b__2>d.MoveNext()
--- End of stack trace from previous location ---
at NSwag.AspNetCore.Middlewares.SwaggerUiIndexMiddleware.Invoke(HttpContext context)
at NSwag.AspNetCore.Middlewares.RedirectToIndexMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
Hi! I can't reproduce your issue using the sample code in the template. When I try, I get the expected response:
Based on your screenshots and error message, I can see that the request is correctly validated and that the appropriate exception is thrown. The last piece of the puzzle is within ./src/Web/Infrastructure/CustomExceptionHandler.cs. This class is responsible for handling exceptions thrown by the application. For known exception types, it will return a problem details response with the appropriate status code and message.
You can troubleshoot your issue and verify that the CustomExceptionHandler is invoking HandleAsync correctly and ensure that it is returning the appropriate problem details response. Let me know how you go.
Describe the bug
When a validation of a api request body fails the thrown exception doesn't give any details on what exactly failed.
To Reproduce
Steps to reproduce the behavior:
Here the failures has 1 item: {Email is required and must be valid.}
The response i get is the following:
HDN_Component_App.Application.Common.Exceptions.ValidationException: One or more validation failures have occurred.
at HDN_Component_App.Application.Common.Behaviours.ValidationBehaviour
2.Handle(TRequest request, RequestHandlerDelegate
1 next, CancellationToken cancellationToken)at HDN_Component_App.Application.Common.Behaviours.AuthorizationBehaviour
2.Handle(TRequest request, RequestHandlerDelegate
1 next, CancellationToken cancellationToken)at HDN_Component_App.Application.Common.Behaviours.UnhandledExceptionBehaviour
2.Handle(TRequest request, RequestHandlerDelegate
1 next, CancellationToken cancellationToken)at HDN_Component_App.Web.Endpoints.Users.CreateUser(ISender sender, CreateUserCommand command) in D:\Projects\HDN-Component-App\Back-End\src\Web\Endpoints\Users.cs:line 34
at Microsoft.AspNetCore.Http.RequestDelegateFactory.g__ExecuteAwaited|121_0(Task`1 task, HttpContext httpContext)
at Microsoft.AspNetCore.Http.RequestDelegateFactory.<>c__DisplayClass94_2.<b__2>d.MoveNext()
--- End of stack trace from previous location ---
at NSwag.AspNetCore.Middlewares.SwaggerUiIndexMiddleware.Invoke(HttpContext context)
at NSwag.AspNetCore.Middlewares.RedirectToIndexMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
HEADERS
Accept: /
Connection: keep-alive
Host: localhost:5001
User-Agent: PostmanRuntime/7.36.0
Accept-Encoding: gzip, deflate, br
Cache-Control: no-cache
Content-Type: application/json
Content-Length: 183
Postman-Token: 921198c3-f13f-40fb-8c9a-b8ceb7cf104d
How do i get it so that the response is the errors not the stacktrace.
The text was updated successfully, but these errors were encountered: