I have a Controller method as below:
` [HttpGet]
public async Task NonExistentTable()
{
await SqlPipe
.OnError(ex =>
{
this.Response.StatusCode = 500;
throw ex;
}
)
.Stream("select * from NonExistentTable FOR JSON PATH", Response.Body, "[]");
and in the Startup.cs I have as below in the Configure:
` app.UseExceptionHandler(errorApp =>
{
errorApp.Run(async context =>
{
context.Response.StatusCode = 500; // or another Status accordingly to Exception Type
context.Response.ContentType = "application/json";
var error = context.Features.Get<IExceptionHandlerFeature>();
if (error != null)
{
var ex = error.Error;
var err = new ErrorDto()
{
Code = 500,
Message = ex.Message // or your custom message
}.ToString();
await context.Response.Body.WriteAsync(Encoding.ASCII.GetBytes(err), 0, err.Length).ConfigureAwait(false);
}
});
});`
When the NonExistentTable API is called, the exception thrown inside the OnError handler, doesn't get handled in the UseExceptionHandler..
The issue happens only when SqlPipe.Stream is used, any other exception thrown from other methods gets handled as expected..
What am I missing here?
I have a Controller method as below:
` [HttpGet]
public async Task NonExistentTable()
{
await SqlPipe
.OnError(ex =>
{
this.Response.StatusCode = 500;
throw ex;
}
)
.Stream("select * from NonExistentTable FOR JSON PATH", Response.Body, "[]");
and in the Startup.cs I have as below in the Configure:
` app.UseExceptionHandler(errorApp =>
{
errorApp.Run(async context =>
{
context.Response.StatusCode = 500; // or another Status accordingly to Exception Type
context.Response.ContentType = "application/json";
When the NonExistentTable API is called, the exception thrown inside the OnError handler, doesn't get handled in the UseExceptionHandler..
The issue happens only when SqlPipe.Stream is used, any other exception thrown from other methods gets handled as expected..
What am I missing here?