AspNetCore.CacheOutput icon indicating copy to clipboard operation
AspNetCore.CacheOutput copied to clipboard

CacheOutput Eating Exception Handler

Open xingwen1987 opened this issue 5 years ago • 11 comments

CacheOutput version 2.0.2 Eating Exception Handler.

without CacheOutput, the code beyond: image response is: image

enable CacheOutput, the code beyond: image response is none! image

xingwen1987 avatar Sep 14 '21 14:09 xingwen1987

Hey,

What is the status code of the response when the exception occurred? Is this cacheable? Can you provide more details on the exception handler implemented and registered in Startup.cs?

Iamcerba avatar Sep 14 '21 20:09 Iamcerba

Status Code when the exception occurred is 0,in Startup.cs file,registered component as document says: image And our platform has a middleware to handler custom exception,the code as followed: image if not enable cacheoutput, can return correct, image but enable cacheoutput, return empty, image

xingwen1987 avatar Sep 15 '21 02:09 xingwen1987

So you are expecting to see exactly the same cached result (HTTP 200 is cacheable by default)?

Can you create a minimal viable example of the application with your middleware so I will be able to reproduce it?

Iamcerba avatar Sep 20 '21 10:09 Iamcerba

Hey @Iamcerba I bumped into the same issue. Created an example here https://github.com/abzubarev/Test.CacheOutputEatingExceptions

abzubarev avatar Oct 17 '21 23:10 abzubarev

@abzubarev I will take a look later. Seems like something was broken after https://github.com/Iamcerba/AspNetCore.CacheOutput/pull/15

Thanks!

Iamcerba avatar Oct 18 '21 06:10 Iamcerba

@abzubarev I've created a release 2.0.3 that should fix the issue.

@mgoodfellow I've reverted your https://github.com/Iamcerba/AspNetCore.CacheOutput/pull/15 as well until another working solution will be found.

Iamcerba avatar Oct 18 '21 08:10 Iamcerba

@Iamcerba already fixed - seems I only had a min to look when you reverted the change out. It isn't a complex issue - just need to check the result of next() and if it fails, we swap the memory stream back over

mgoodfellow avatar Oct 18 '21 08:10 mgoodfellow

Thanks a lot, didn't have much time to work on it so reverted... Will take a look at a fix. Appreciate.

Iamcerba avatar Oct 18 '21 08:10 Iamcerba

No worries - I personally wasn't affected as we use the middleware pipeline to check for exceptions rather than layers of filters. I think that is the more common approach nowadays - maybe why it hasn't been reported sooner? Apologies though, it seems I overlooked one result edge case when looking for points to swap back the MemoryStream.

Would be good to revert the revert, and then merge in https://github.com/Iamcerba/AspNetCore.CacheOutput/pull/22 if possible! Thanks

mgoodfellow avatar Oct 18 '21 08:10 mgoodfellow

Agree that middleware for exceptions handling is a more common practice. Hopefully, I will find additional time to start working on integration and unit tests.

Iamcerba avatar Oct 18 '21 08:10 Iamcerba

2.0.3.1 which resolves this issue has been released.

Iamcerba avatar Oct 18 '21 08:10 Iamcerba