I want to send a email when I get 500 error in project | I want to handle 500 internal server error

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);
    };
};

thanks in advance!

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.

Have you checked your PHP error logfiles?

![Screenshot from 2023-10-13 14-38-26|690x201](upload://mvn5Kmzbrhdlou0ayngRAEMx2qd.png

Can you please add more details. The image was also not uploaded.


Odan, Please find screenshot:

It looks like an issue with an XML / HTTP request or something in the Media Type Parser in Slim 3.

You can consult me if you need assistance. Just send me a direct message.

@odan Where I can connect/DM to you ?

Just click on my Profile link and then use the “Message” button.

I don’t know if it is your problem, but you can set handlers for error’s, exceptions and for shutdown.