winter/modules/backend/traits/ErrorMaker.php
Ben Thomson a59d3b83eb Code quality clean up (#4449)
Credit to @bennothommo
2019-07-18 08:50:37 -06:00

45 lines
1004 B
PHP

<?php namespace Backend\Traits;
use System\Classes\ErrorHandler;
/**
* Error Maker Trait
* Adds exception based methods to a class, goes well with `System\Traits\ViewMaker`.
*
* @package october\backend
* @author Alexey Bobkov, Samuel Georges
*/
trait ErrorMaker
{
/**
* @var string Object used for storing a fatal error.
*/
protected $fatalError;
/**
* @return boolean Whether a fatal error has been set or not.
*/
public function hasFatalError()
{
return !is_null($this->fatalError);
}
/**
* @return string The fatal error message
*/
public function getFatalError()
{
return $this->fatalError;
}
/**
* Sets standard page variables in the case of a controller error.
*/
public function handleError($exception)
{
$errorMessage = ErrorHandler::getDetailedMessage($exception);
$this->fatalError = $errorMessage;
$this->vars['fatalError'] = $errorMessage;
}
}