https://book.cakephp.org/3/en/development/errors.html#id7
I want to check if errors other than Warning can be detected with the error handler added based on the official document
Notify the system administrator when an exception other than 404 described in error.log occurs in the system.
The following error handler is created to notify you when there is a system error
I apologize for being mixed up and down, but I understand that the types of errors that can be detected are within this error level and are configured to be accepted by logs in the app.php file.
First of all, is this understanding correct?
https://book.cakephp.org/3/en/core-libraries/logging.html
Applicable source codeEmergency: System is unusable
Alert: Need to act now
Critical: Critical condition
Error: error condition
Warning: Warning condition
Notice: Normal but critical condition
Info: Information message
Debug: Debug level message
<? php
namespace App \ Error;
use Cake \ Error \ BaseErrorHandler;
use Cake \ Core \ Configure;
use Cake \ Controller \ ComponentRegistry;
use App \ Controller \ Component \ MailComponent;
class AppError extends BaseErrorHandler
{
public function _displayError ($error, $debug)
{
$level = $error ["error"];
$systemError = array (
'level' =>$error ["error"],
'description' =>$error ["description"],
'file' =>$error ["file"],
'line' =>$error ["line"]
);
if ($level! = 'Warning'&&$level! = 'Notice'&&$level! = 'Debug') {
$mail = new MailComponent (new ComponentRegistry ());
$mail->sendSystemError ($systemError);
}
}
public function _displayException ($exception)
{
$systemException = $exception->getMessage ();
$mail = new MailComponent (new ComponentRegistry ());
$mail->sendSystemException ($systemException);
}
}
Attempting to generate an error by creating and accessing such a controller
If i make a request with an account that does not exist in the external API, Error.log will appear as Error, so I thought it would be possible to get the content that appears in error.log with an error handler
However, such errors cannot be detected by error handlers
I don't know how to intentionally generate an error other than Warning, and I can't verify that it can actually be detected. What should be the verification method in this case?
<? php
namespace App \ Controller \ Admin;
use App \ Controller \ AppController;
use Cake \ Core \ Configure;
use Cake \ Chronos \ Chronos;
use Cake \ I18n \ Time;
use Cake \ Core \ Exception \ Exception;
use Cake \ Http \ Exception \ InternalErrorException;
use Cake \ Datasource \ Exception \ RecordNotFoundException;
class DebugsController extends AppController {
...
public function send_error () {
\ Payjp \ Payjp :: setApiKey ("testtest");
\ Payjp \ Charge :: create (array (
"card" =>"tok_XXXXXX",
"amount" =>3500,
"currency" =>"jpy"
));
}
}
...
Sorry for the hard-to-read document
Isn't it an implementation for the requirements I want to meet fundamentally? Or if you have any need for this information, thank you for pointing it out
-
Answer # 1
Related articles
- error in import xlrd of python file from cakephp
- excel - macros that work normally on my pc stop with an error on the way on other pcs
- cakephp: error regarding permission denied (cakephp super introduction: cakephp40)
- cakephp 4: i get an error when uploading a file without input
- i don't get a compile error with vscode, but i get a warning typescript
- c# - i want to generate an installation error if an existing file is not updated during installation
- compiler - reps + typescript does not generate a type error when accessing even though props is set to optional
If you want to generate an error in php, use
trigger_error
.PHP: trigger_error-Manual
SupplementUsing components to send email is redundant. Use mailer classes.
Creating reusable emails-Email-3.8
Rather than overriding_displayError
,_displayException
, overridehandleError
,handleException
I think it ’s smarter to readIf you just want to be notified by email in case of an error, you can use the fusic/encount plugin.