tommy
March 11, 2016, 9:13am
1
Enonic version: 6.4.1
OS: OSX
Is it possible to throw a 404 from a part?
var content = (req.params.id) ? contentLib.get({ key: req.params.id }) : null;
if (!content) {
return {
status: 404
}
}
This will only render the page with no content where the part should have been. I would rather like to show our global 404-page.
1 Like
bwe
March 11, 2016, 9:25am
2
Hi,
Add the redirect param in the return statement =) With it you could redirect to the global page (fetch from settings in site.xml or from part or where ever you have it).
tommy
March 11, 2016, 9:40am
3
Hm, this doesn’t seem to work. I get the same result. That is, the page with an empty part without the part.
if (!content) {
return {
redirect: "/some-page"
}
}
bwe
March 11, 2016, 11:16am
4
Sorry, I tricked you a little. Parts can’t redirect, only pages. Unless the part is handling the request as a post … I think.
Why should the part throw the 404? You could print “Article not available” or something too?
tommy
March 11, 2016, 11:19am
5
Ah, thanks for clarifying! Sounds good. Thanks for your help.
bwe
March 16, 2016, 8:47am
6
Did you get your error handling to work in the end?
tommy
March 16, 2016, 8:59am
7
Yes. As you suggested we just print “Article not found” instead of showing our generic 404.
You can close this issue.
1 Like