I am using Slim framework 3.1 version in my project and I want to perform a action (e.g. send a email to admins/ show some message) when I get 500 internal server error in my project/script.
Now I am using phpErrorHandler to handle this but it is unable to catch/handle to all type of 500 error. So please help me out to do this.
Example (currently what I am using, but it is unable to handle) :-
$container['phpErrorHandler'] = function ($container) {
return function ($request, $response, $error) use ($container) {
// call sen email function
// set the message to show in my project
return $response->withJson($responseData);
};
};
I tried this also but this is also unable to handle this:
$container['errorHandler'] = function ($container) {
return function ($request, $response, $error) use ($container) {
// call sen email function
// set the message to show in my project
return $response->withJson($responseData);
};
};
Depending on the type of error this should be handled by Slim. For example all “Exception” types should be handled by “errorHandler” and all “Throwable” types should be handled by “phpErrorHandler”.
If this is not the case, then there is a chance that somewhere in your code, triggers a different (older) type of PHP errors, such as a fatal error. This type of errors will not be processed by the mentioned default Exception/Throwable handlers.