Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect 404 in the Middleware #1291

Closed
sneerin opened this issue Nov 15, 2018 · 2 comments
Closed

Detect 404 in the Middleware #1291

sneerin opened this issue Nov 15, 2018 · 2 comments

Comments

@sneerin
Copy link

sneerin commented Nov 15, 2018

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

I can't detect within the middleware if the route exists, my auth module based on path, so naturally all requests become 401 thought it's 404, it's very confusing for users.

Expected behavior

404 happens before middleware or there is a way to detect it during middleware and throw a 404 error manually.

Minimal reproduction of the problem with instructions

in the middleware I'm doing that:

const permissions: IPermissionsResult = await perms.isAllowed(key, replaceDelimiter(req.baseUrl), mapActions(req.method));

if (!permissions.granted)
next( new UnauthorizedException('error message goes here'))

changing it to throw also didn't help, so the only solution I have is to put error flag to request as a parameter and then throw it there, which is ugly.
I did implement the BaseExceptionFilter, but it also caught only the error I throw, not the 404 error.

What is the motivation / use case for changing the behavior?

Environment


Nest version: 5.4.0

 
For Tooling issues:
- Node version: 9  
- Platform:  

Others:

@sneerin sneerin changed the title Detect 404 during Middleware Detect 404 in the Middleware Nov 15, 2018
@kamilmysliwiec
Copy link
Member

I'd suggest tracking this issue #1030 which should enable generation of all routes defined in your app (then you could simply iterate through an array and in case of a missing endpoint, throw 404 error)

@lock
Copy link

lock bot commented Sep 24, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants