blessing-skin-server/app/Exceptions/E.php

38 lines
894 B
PHP
Raw Normal View History

2016-03-27 11:38:27 +08:00
<?php
2016-07-21 22:01:57 +08:00
namespace App\Exceptions;
class E extends \Exception
2016-03-27 11:38:27 +08:00
{
/**
* Custom error handler
*
* @param string $message
* @param integer $code
* @param boolean $render, to show a error page
*/
2016-07-21 22:01:57 +08:00
function __construct($message = "Error occured.", $code = -1, $render = false)
{
2016-03-27 11:38:27 +08:00
parent::__construct($message, $code);
if ($render) {
$this->showErrorPage();
} else {
$this->showErrorJson();
}
}
2016-07-21 22:01:57 +08:00
private function showErrorJson()
{
2016-03-27 11:38:27 +08:00
$exception['errno'] = $this->code;
$exception['msg'] = $this->message;
@header('Content-type: application/json; charset=utf-8');
2016-03-27 11:38:27 +08:00
exit(json_encode($exception));
}
2016-07-21 22:01:57 +08:00
private function showErrorPage()
{
2016-07-22 13:48:33 +08:00
echo \View::make('errors.e')->with('code', $this->code)->with('message', $this->message);
2016-03-27 11:38:27 +08:00
exit;
}
}