Welcome Guest, Not a member yet? Register   Sign In
How to make email notifications for errors and exceptions?
#1
Question 

How to make email notifications for errors and exceptions without changing the file /system/Debug/Exceptions.php?
I want to change error handling without changing engine code!
Reply
#2

Isn't this possible in `App\Config\Exceptions` or are you looking for a different solution?
Reply
#3

(This post was last modified: 01-30-2023, 06:38 PM by kenjis.)

You can't now.
You need to replace Exceptions.
Reply
#4
Question 
(This post was last modified: 01-31-2023, 02:25 AM by krotovroman.)

(01-30-2023, 06:36 PM)kenjis Wrote: You can't now.
You need to replace Exceptions.
That is, without files in the system folder, is this impossible?

(01-30-2023, 05:51 AM)superior Wrote: Isn't this possible in `App\Config\Exceptions` or are you looking for a different solution?

Can you write a sample code how can i do it without editing folder @"system"? Please!
Reply
#5

See https://codeigniter4.github.io/CodeIgnit...asses.html
Reply
#6

I monitor /writable/logs folder for files every 15 min. If there is error file - script send me motification via telegram or email.
Reply
#7

(This post was last modified: 02-19-2023, 12:50 AM by krotovroman.)

I try it, but this is not work. What is wrong?

[Image: LEWuPY.jpg]
PHP Code:
<?php
namespace App\Libraries;

use 
CodeIgniter\API\ResponseTrait;
use 
CodeIgniter\Exceptions\PageNotFoundException;
use 
CodeIgniter\HTTP\CLIRequest;
use 
CodeIgniter\HTTP\Exceptions\HTTPException;
use 
CodeIgniter\HTTP\IncomingRequest;
use 
CodeIgniter\HTTP\Response;
use 
Config\Exceptions as ExceptionsConfig;
use 
Config\Paths;
use 
ErrorException;
use 
Psr\Log\LogLevel;
use 
Throwable;

/**
* Exceptions manager
*/
class Exceptions extends Exceptions
{
    /**
    * Gathers the variables that will be made available to the view.
    */
    protected function collectVars(Throwable $exceptionint $statusCode): array
    {
        $trace $exception->getTrace();

        if ($this->config->sensitiveDataInTrace !== []) {
            $this->maskSensitiveData($trace$this->config->sensitiveDataInTrace);
        }

        $return = [
            'title'  => get_class($exception),
            'type'    => get_class($exception),
            'code'    => $statusCode,
            'message' => $exception->getMessage(),
            'file'    => $exception->getFile(),
            'line'    => $exception->getLine(),
            'trace'  => $trace,
        ];
        
        
//send email
        mail('[email protected]''test');

        return $return;
    
Reply
#8

I think "class Exceptions extends Exceptions" does not work.
It seems fatal error.

And the collectVars() method works only in development mode.
Reply
#9

(01-31-2023, 05:14 PM)kenjis Wrote: See https://codeigniter4.github.io/CodeIgnit...asses.html

(02-19-2023, 07:18 PM)kenjis Wrote: I think "class Exceptions extends Exceptions" does not work.
It seems fatal error.

And the collectVars() method works only in development mode.

yes I use now development mode.
how to fix it to work?
Reply
#10

Exceptions::exceptionHandler() is the exception handler.
Override the method.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB