I want all codeigniter errors to be redirected to a custom error page. I have redirected 404 errors with $route['404_override'] = 'errorcontroller'; How can I redirect all the other errors such as db and php
You can always use try and catch block and then redirect to your custom error page. But as per your questions, there are some things you should consider.
Redirect will issue a completely new request which is accomplished with the header sent to the browser. For that reason you will not be able to display the error message unless you save that message in session or something.
Some errors results in PHP throwing exceptions while others don't. Some DB interactions error only raises PHP warnings or error. PHP execution may halt but no exception will be thrown. In such case even wrapping the code in try catch will not be any help. However, you can create a custom error handler and inform PHP to use that handler. Then in the custom error handler you are free to throw exceptions or redirect to error page.
you can also use .htaccess to force redirection to the pages you set at specific header codes [404,304,500] etc
Hope this helps!
Related
I do maintenance on a classic ASP website that basically has no error handling at all yet. So users see any error message that comes across... Instead, I would like my code to be able to catch any potential error and then fire off an email before redirecting the user to a more friendly error-page.
This website is rather large, and every webpage comes with the same include file at the beginning... So ideally, I would like to set an error handler from the beginning of this include file. I haven't had any luck finding a way to do this without having to go through every page individually having error handling happen at the end of the script... Is there a possible way to code something like this from the include file?:
' Include file contents:
Function MyHandler()
'Code for triggering email goes here
response.redirect "ErrorPage.asp"
End Function
On Error call MyHandler()
Thanks in advance!
I suggest to use Custom Error Pages in IIS (Web Server), if you have access to those. You can redirect different types of errors to different scripts if you like or point them all to a single one and have there the logic for all error codes.
You can catch common errors there and maybe redirect the user to a alternative page/site, or return a specific error message.. I would suggest to use the custom error page also to log the error and some information from the session (e.g. form submit data, query strings, referrer URLs, cookies etc.) in a database and/or send a notification email to some service account to identify specific issues that are occurring and then also have something to go on to actually fix the cause of many of the errors.
I'm using OpenCart 1.5.1.3 and having this strange error on Guest Shipping in Ajax. I'm getting the error "Unexpected token <".
I have tried everyting, change the Ajax code, look at the controller, but no luck. You can try it yourself at http://www.biancabonte.nl/shop/. Put something in the cart and checkout Direct instead of registering. Then the problem occurs.
Thanks
This is almost certainly due to an error message being output by your store, which precedes the AJAX JSON content. Check your error logs around the time you made/make the request. While they won't contain the < character since they're not formatted like the ones output by PHP, they will still have the actual message. Your error logs will either be in the SYSTEM > ERROR LOGS in the admin, or in your cpanel/plesk/other control panel under logs usually
In my module's code, I echo'd an undefined variable:
echo $doesnotexist;
I have done the following in index.php:
error_reporting(E_ALL);
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
This combination shows a "Whoops, our bad..." 404 type page when the code is executed. And in the exception.log there is a Notice ("Undefined variable: doesnotexist") as well as a stack trace.
If I remove part of the instructions in index.php:
error_reporting(E_ALL);
//Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
The frontend shows the page normally without any indication of the error, and the error is logged to system.log.
Now my question is: Is there a way to output these notices/errors directly to the frontend? Or am I supposed to always keep open a copy of system.log or exception.log while coding?
Magento normally uses zend exception/error handling class for the error and exception handling. So for the errors in which magento code send exception is logged in your log.
But if the error is not catchable by magento then it will be printed on your page.
You can get your error on frontend in 2 case:
If you are creating your own magento extension then you can throw your error in the way so that it can get displayed on magento page
If you are working on .phtml file and getting fatal errors
As a security concern errors and warning s should not be displayed on front end.
If there is an exception or you do some system log you will be able to get that from system.log or exception.log
For PHP errors you should refer to error log file that is generated at site level.
Mage::setIsDeveloperMode(true); can be used only after you have included Mage.php so paste your complete index.php code
Is there a way in Codeigniter to override global errors. For instance if an DB error or PHP critical occurs it wont show the error itself but something like 'Our admin guy is fixing the issue' and the error is just logged and emailed.
Codeigniter lets you handle error messages your way, depending on the HTTP status.
Refer to this documentation on error handling
In addition to #Pos5e5s3dFr3ak's answer, you should handle as many errors as you can manually. For example, if you have a database error, your code should acknowledge (or 'catch') it and perhaps load the appropriate view, or pass it onto a library that will log an email the fault, instead of displaying the intended result.
This method can be used as an alternative, or as an addition to the original answer - sometimes you need not locate the error just by its HTTP response Status Code.
As an example, you may find that the database engine in use is down. If this is the case (you would have to determine if it is indeed down - ie. you are not getting the desired response), you would pass the user on to example.com/error/database, for example.
Is there a way to redirect the user to an error page (view) when an exception is raised in application_start method of global.asax? I get a Request object is null message when I try to do a redirect. How would i handle this? I have to raise the exception if certain conditions are not met and I want the user to go to a specific View.
My application is MVC3 based, btw.
Thanks
Application_Start happens before ASP.Net starts processing the request.
You could set a global static flag to indicate the error condition, then handle BeginRequest and check the flag and redirect.
You can refer this page.
The thing you are trying to do is possible via Web.config Just show what page to load when http error 500 occurs.
Edit
Sorry gave wrong url