Here it is our middleware's code snippet
public Task InvokeAsync(HttpContext context)
{
if(!found)
{
context.Response.StatusCode = StatusCodes.Status401Unauthorized;
return context.Response.WriteAsync("Something wrong");
}
return _next(context);
}
The problem is that while the client app receives error code 401 which is fine but "Something wrong" string is not found in the response's body. What are we missing here?
An interesting solution that worked for us:
The following statement:
return context.Response.WriteAsync("Something wrong");
was replaced by this one:
return context.Response.Body.WriteAsync("Something wrong").AsTask();
This change made the response be populated properly. Although, I'm not sure yet why this way of response body population would work but not the initial method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With