Answer the question
In order to leave comments, you need to log in
An exception was thrown while loading the page. Which page to redirect to?
I load the pages of the site through the following block:
try{
// Код загрузки страницы
// Тут подключаются другие файлы и т.д.
}catch (Exception $e){
// ???
}
If an exception was thrown while loading the page, do I need to redirect to the error page? Is there a specific code for this kind of error? Does this mean that something happened on the server? How search engines will react to the redirect of the main page if an exception 0_0 is thrown during indexing
Answer the question
In order to leave comments, you need to log in
A redirect in case of an error is impossible.
Because in case of an error, the server is obliged to return the HTTP status with the 5xx code
. And the redirect gives the 3xx code.
That is, if you make a redirect, the client will not know that this is an error.
When errors occur, the behavior of the combat server should be standard:
1. log the error for the programmer
2. Give the correct status code for the HTTP client
3. If the request was made by the browser, then it is desirable to show the site visitor some meaningful page.
You can, by the way, do without try-catch. Did I understand the centralized exception handling in PHP correctly?
Correctly issue a 503 error, where does the redirects and how they arose in your brain, God only knows
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question