Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem:
If exception raises on Nest side - server doesn't flush any response to client at all.
Network request in browser just spins, because Next code deadlock on
this.ready
inside NextCustomServer impl.Here was issue: vercel/next.js#54977
One highlight from that issue: we cannot use "renderError" method anyway - because somebody (who has permissions to close tickets) says that it's "not public", while typescript typings says that it's public.
Anyway, when you set:
passthrough404: true
404 error will be rendered by Next - everything fine.But any other error will get stuck. For example NPE --> unflushed request.
If you set
passthrough404: false
- then just all errors stuck on server.So idea of fix is simple: pass error handling to Nest itself, let if deal with that.
Because before this fix, in RenderModule there was
this.service.setErrorRenderer(next.renderError.bind(next));
So effectively you was passing error to Next, as final fallback.
After this fix, I just call default exception handler's impl -
BaseExceptionFilter
.Ideally I would make
RenderFilter extends BaseExceptionFilter
and just dosuper.catch(...)
inside.But that would be bigger refactoring and there is already very helpful
renderService.getErrorRenderer
for some reason.