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
Every requests frombody parameter became empty #22
Comments
Hi @attilaszabo2 - Thank you for the feedback! I may have to look into it and do some testing to verify it. I haven't tried using Also, what is the second middleware that you are using? |
The other middleware is a custom one, which does nothing, it is just a secondary exception handler, which handles the custom backend exceptions and cast them to |
What happens if your comment out the other middleware? |
Unfortunately nothing, I still get the same response: |
@attilaszabo2 Thank you. I'll look deeper into this. |
@proudmonkey I actually created a new feature branch, where I added a simple webapi app and wrote the integration test, so now you can check it, reproduce the error or even debug. |
@attilaszabo2 I'm able to replicate it. I'm refactoring the code and will roll-out a new version release soon. I'll keep you posted. Thank you for you feedback! :) |
Sorry, I think this is not relate to this issues, but |
@arhen Yes. You can define your own |
This is interesting. public class ExceptionMiddleware
{
private readonly RequestDelegate _next;
private readonly ILoggerManager _logger;
public ExceptionMiddleware(RequestDelegate next, ILoggerManager logger)
{
_logger = logger;
_next = next;
}
public async Task InvokeAsync(HttpContext httpContext)
{
try
{
await _next(httpContext);
}
catch (Exception ex)
{
_logger.LogError($"Something went wrong: {ex}");
//await HandleExceptionAsync(httpContext, ex); //my previous method to handle exception
await HandleApiExceptionAsycn(httpContext ex); //This is my method that I want to the exception wrapping out by ApiException from AutoWrapper
}
}
private Task HandleExceptionAsync(HttpContext context, Exception exception)
{
context.Response.ContentType = "application/json";
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
return context.Response.WriteAsync(new ErrorDetails()
{
StatusCode = context.Response.StatusCode,
Message = "Internal Server Error."
}.ToString());
}
private task HandleApiExceptionAsync(HttpContext context, Exception exception)
{
//IMPLEMENT ApiException handling from AutoWrapper
}
} then register As u can see above, I have no idea to implement my own custom and pass it to ApiException then use this middleware as ExceptionHandler on pipelane. I'm using |
Just released a new version that comes with a fix for this issue. You can find it here: AutoWrapper Now Supports Problem Details For Your ASP.NET Core APIs Thank you so much for all your suggestions on improving this middleware! :) |
Hi,
I found an edge case when your middleware causing a weird problem.
In my .net core 3.1 application I tried to create HttpClient from WebApplicationFactory because I wanted to write an integration test for a POST request.
The problem is that this request is containing a (FromBody) parameter, which could not be found after I was registered your middleware btw I'm using a second middleware. Actually I don't really know what is the root cause of the issue but I found the solution.
Can you please change the following code in the
AutoWrapperMembers.FormatRequest
method?from
to
Because it looks like that the request.Body.ReadAsync closes the request body stream anyway, even if you executing the request.Body.Seek().
Best regard,
Attila
The text was updated successfully, but these errors were encountered: