I have a django backend and a angular/ui-router frontend. I would like to handle 404 errors (and 400, 403 and 500) on the frontend side. Meaning:
A client send a bad url (page not found)
I catch the exception with a custom error handler on the backend side
Return the 404
Magic!
The frontend redirects to something like www.example.com/#/error404
I could just return a django.shortcut.redirect from the backend side but I read here that crawlers from search engines do not like when you do not return a 404 error code on unknown page. With a redirect I'd be returning a 302...
Or is it just wrong to manage error pages on the client side ? This would be a shame because everything is managed by the frontend (header, footer, etc) so the 404 page would not be following the standard page layout.
Check out interceptors here,
https://docs.angularjs.org/api/ng/service/$http
Once you set that up, you should be able to redirect to a page according to the error you process.
Related
we are using Vercel for making development fast .
in our react app , after payment page when payment redirect to our given url it gives 405 http error, how can we handle this?
I finally found the problem , it is coming from PayTabs's side
followings are the logic they are handling wrong:
when nothing is received from callback url , they should not redirect us with given redirect url
when we are giving an invalid callback url it make a GET request to given redirect url
when we are giving an valid callback url which returns 200 to them it make a POST request to given redirect url which is not supported by browser.
This error happens when your page does not use next js serverside rendering. I had same issue but solved it by converting the page from a static page to a server rendered page using getServerSideProps
How can I return 404 status code in React (with react-router-dom)?
<Route component={NotFoundPage} path="*" />
The answers I got can return a 404 page, but not the http status code. Is there any way around that?
React runs on the client. Under normal circumstances, you can't generate a 404 error response because there is no request or response at all.
If you were using some server-side renderer (such as Next.js) then it would likely provide a method for generating a 404 error, but it would be specific to that SSR framework.
Your Js or any client side service doesnt return response with code. You can get 404 status code from server. In front end there is no way to send status code. Status code is sent by server depending on the request sent by Client side app.
I'd like to send a 404 error, and re-direct to a more attractive Error page for the user on Google App Engine.
I've tried adding this to my web.xml, but it doesn't work
<error-page>
<error-code>404</error-code>
<location>404.html</location>
</error-page>
The only information I have discovered comes from the old Google group
https://groups.google.com/d/topic/google-appengine-java/3C-pY5ta2HQ/discussion
I'd like to send the proper 404 header for search engines, and I'd like to present a nicer Error message to the user. Jason's suggestion at the end would mean sending a 302 and not a 404 so I don't think that is ideal for search engines. Is that the only choice? Any help, views appreciated.
Custom 404 pages are not supported for URLs your app handles, because once the request is directed to your application, it's up to it to return the response to the user. If you want to render an attractive 404 page, you should have your app return that as its response to a request that generates a 404. How you do that - via an internal redirect (not an HTTP one!) - or other functionality is up to you.
So Im having quite trouble to get speaking URLs in TYPO3. I managed to make them work with this 2 lines in localconf.php
$TYPO3_CONF_VARS["FE"]["pageNotFound_handling"] = 'http://www.mysite.com/';
$TYPO3_CONF_VARS["FE"]["pageNotFound_handling_statheader"] = 'HTTP/1.1 404 Not Found';
But the problem is that if I type a inexisting page, it even though it will direct me to the homepage, it wont rewrite the URL in the browser. Is there something that can be done about this?
It's the correct behavior of 404 not to change the URL in the browser. For redirects we have 30x http status codes. But you can't send two http status codes at the same time (404 and 301).
It is kind of bad practice to redirect to a homepage instead of showing a 404-not found message. The users may be irritated, asking themselves why they are now on the homepage and not at the URL they typed in...
I am building facebook app using iFrame (using Google App Engine Java,JSP and Facebook-api-java), and when Facebook calls back to my website, I expect to get the fb_sig_* request params for the iFrame, but I get those params in HTTP referer header instead.
When I use the php client, i get the fb_sig_* in the $[_GET] as expected.
What have I done wrong?
Thanks
If you get them in the referrer, then it means that a redirect has taken place. If this is not the expected behaviour by Facebook, then you need to ensure that you don't have some Servlet or Filter in the request chain which redirects requests using HttpServletResponse#sendRedirect() for some reason.