Hi,
I'm using PushStreamContent in asp.net web api to stream data to the client, I have derived from ExceptionFilterAttribute to capture all the exceptions and return standard HttpError to client. However,
I found that exception thrown inside PushStreamContent won't be caught by ExceptionFilterAttribute, it will return a "text/html" error message to client.
Below is the sample code:
response.Content = new PushStreamContent(
async (outputStream, httpContent, transportContext) =>
{
try
{
// do something and throw exception here
}
catch (Exception ex)
{
throw;
}
finally
{
outputStream.Close();
}
});
Comments: This is an expected behavior I think. The PushStreamContent's delegate is invoked way below in the stack (at hosting layers), so any exception thrown at this layer wouldn't be caught in exception filters.
I'm using PushStreamContent in asp.net web api to stream data to the client, I have derived from ExceptionFilterAttribute to capture all the exceptions and return standard HttpError to client. However,
I found that exception thrown inside PushStreamContent won't be caught by ExceptionFilterAttribute, it will return a "text/html" error message to client.
Below is the sample code:
response.Content = new PushStreamContent(
async (outputStream, httpContent, transportContext) =>
{
try
{
// do something and throw exception here
}
catch (Exception ex)
{
throw;
}
finally
{
outputStream.Close();
}
});
Comments: This is an expected behavior I think. The PushStreamContent's delegate is invoked way below in the stack (at hosting layers), so any exception thrown at this layer wouldn't be caught in exception filters.