Skip to content

Errors thrown in SqlPipe.OnError do not propagate to middleware Error Handler #3

@ganeshmuthuvelu

Description

@ganeshmuthuvelu

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions