20240413#7

This commit is contained in:
User
2024-04-13 11:33:47 +03:00
parent 041ee17263
commit cb5408be4a
24 changed files with 16 additions and 15 deletions

View File

@@ -0,0 +1,35 @@
<?php
namespace Base\Controllers;
use Base\Repository\RepositoryException;
use Base\Services\DTOException;
use Base\Services\ServiceException;
use Exception;
use Throwable;
abstract class AbstractPageController extends AbstractController {
/**
* @param Exception $exception
* @param array $data
* @return void
*/
public function exceptionPage(Exception $exception, array $data = []) : void {
$this->logException($exception, $data);
$this->syslogger()->warning($exception->getMessage()." on ".$exception->getFile().":".$exception->getLine(), $data);
$this->template()->setSubtemplate("main", "/templates/error/errpage.tpl", [
"errorText" => "<span style='color:red'>Error: ".$exception->getMessage()." (".$exception->getCode().")"."</span>"
]);
}
/**
* @param Throwable $e
* @return string
*/
public function checkError(Throwable $e) : string {
if($e instanceof DTOException || $e instanceof ServiceException || $e instanceof RepositoryException) return $e->getMessage();
($e instanceof Exception) ? $this->logException($e) : $this->logError($e);
return "Ошибка. Дата и время: ".date("d-m-Y H:i:s");
}
}