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;
|
2016-04-02 22:53:55 +08:00
|
|
|
@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-23 14:10:53 +08:00
|
|
|
echo \View::make('errors.e')->with('code', $this->code)
|
|
|
|
->with('message', $this->message)
|
|
|
|
->render();
|
2016-03-27 11:38:27 +08:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|