-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Trigger a 404 from within view #1249
Comments
try instead of passing the error, throwing it right then and there. I think that would produce a 500 error btw. |
Yes throwing there causes an uncaught exception. I could use the response object directly, but then would have to implement custom 404's for each route. I was hoping to just pass it along to the default handler. |
I think this is what you are looking for: if (result.length === 0) {
return res.status(404).send(keystone.wrapHTMLError('Sorry, no page could be found at this address (404)'));
}
On a final note, the if (result.length === 0) {
return res.status(301).redirect('/');
} |
@albertogasparin Thanks for pointing out |
+1 - being able to pass errors out of the view back up for appropriate handling would be useful. |
Any advance on this? I've started writing my first keystone app by following the tutorial, which initializes a So, on a given "view route handler", when i'm accessing the database to lookup a given slug for a doc, and it's not found, should i call that |
@jacargentina did you try that? I think |
Sorry for the late response on this. This should definitely be possible, if it isn't that's a bug. If one of you could try it with the current |
@mxstbr No worries at all. Thanks for all the work you have been doing. Did you mean "its a bug" if you can't pass errors out of View back to the express? I just pulled master and that is still the case. If you meant when I said
That was my error. I was probably calling |
Oh right, I didn't know #1257 exists! I'll poke @JedWatson to take a look. |
@mxstbr i think there needs to be a method for destroying the view. i get an error about the headers already being sent |
How to customise 404 error page ? ( for eg. to add some links to homepage or something like that ) ? |
Keystone 4 is going in maintenance mode. Expect no major change. see #4913 for details. @albertogasparin's comment is the best solution/workaround for v4. |
Is there a way to pass an error out of a view to be handled by the default handlers in Keystone? What I was hoping to do was pass along a 404 if a query returned no results. Passing an error to next() doesn't stop the view from rendering.
The text was updated successfully, but these errors were encountered: