mardi 2 janvier 2018

Echo errors when debug = false

In my Laravel 5.5 application I have for the site when in production a custom error 500 blade. In this error blade there is a call to a function to send me as developer a mail message as an alert there is an error in the site.

I have already included some extra info like, URL, Referrer, User IP etc. but I would also like to have the error included in that mail, as now I have to manually find the issue at hand in the logfiles, while if I had the error in that same mail message it would be easier for me to tackle the issue. I am mainly asking as in my application there are 500 errors which I cannot reproduce.

Here is the code for the mailer:

public static function sendOutAlert($domain, $url) {
    $ip = $_SERVER['REMOTE_ADDR'];
    if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) {
        $arr =  explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
        $ip = $arr[0];
    }
    $body = '<p>Please have a look at <a href="' . $domain . $url . '">' . $domain . $url . '</a> as soon as possible; An error 500 occurred on this page!</p>';
    $body .= "<p>Some extra info:</p>";
    $body .= "<p>";
    $body .= "Referer: " . $_SERVER['HTTP_REFERER'] . "<br />";
    $body .= "Request method: " . $_SERVER['REQUEST_METHOD'] . "<br />";
    $body .= "User agent: " . $_SERVER['HTTP_USER_AGENT'] . "<br />";
    $body .= "Remote IP address: " . $ip;
    $body .= "</p>";
    $data = [
        'body' => $body,
        'from' => 'noreply@me.com',
        'from_name' => 'ME Mailer Daemon',
        'to' => 'alvin@me.com',
        'subject'=> 'URGENT: Error 500 occurred on live site ' . $domain,
    ];
    Mail::send('emails.main', $data, function($message) use ($data) {
        $message->to($data['to']);
        $message->from($data['from'], $data['from_name']);
        $message->subject($data['subject']);
    });
    return true;
}

Please note that because this is a live web site, the debug is set to false



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2Cbom1F
via IFTTT

Aucun commentaire:

Enregistrer un commentaire