| Current Path : /var/www/html/ebookingdbkl/common/components/ |
| Current File : /var/www/html/ebookingdbkl/common/components/ErrorHandler.php |
<?php
namespace common\components;
use yii\base\BaseObject;
use common\models\ErrorLog;
class ErrorHandler extends BaseObject
{
private static $_errorId;
public static function handle(\Throwable $error, string $module=null,string $action=null,string $path=null) {
self::$_errorId = time() .'UID'. uniqid();
\Yii::$app->session->setFlash('error', \Yii::t('app', '_APPLICATION_ERRORS_') . self::$_errorId);
$error_model = new ErrorLog();
$error_model->hash = self::$_errorId;
$error_model->module = $module;
$error_model->type = 'error';
$error_model->action = $action;
$error_model->stack = $error->getLine() . ' | ' . $error->getMessage() . ' | ' . $error->getTraceAsString();
$error_model->path = $path;
$error_model->created_at = date('Y-m-d H:i:s');
$error_model->created_by = \Yii::$app->user->id ?? '999999';
$error_model->save();
// \Yii::$app->response;
\Yii::$app->response->statusCode = 500;
return self::$_errorId; //do nothing for now
}
}