add custom error handler
This commit is contained in:
parent
80e5623432
commit
b4f1e12c00
|
|
@ -31,7 +31,7 @@ class E extends \Exception
|
|||
|
||||
private function showErrorPage()
|
||||
{
|
||||
echo \View::make('errors.exception')->with('code', $this->code)->with('message', $this->message);
|
||||
echo \View::make('errors.e')->with('code', $this->code)->with('message', $this->message);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
54
app/Exceptions/ExceptionHandler.php
Normal file
54
app/Exceptions/ExceptionHandler.php
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
class ExceptionHandler
|
||||
{
|
||||
|
||||
public static function handler($e)
|
||||
{
|
||||
switch ($e->getCode()) {
|
||||
case E_PARSE:
|
||||
case E_ERROR:
|
||||
case E_CORE_ERROR:
|
||||
case E_COMPILE_ERROR:
|
||||
case E_USER_ERROR:
|
||||
$level = 'Fatal Error';
|
||||
break;
|
||||
|
||||
case E_WARNING:
|
||||
case E_USER_WARNING:
|
||||
case E_COMPILE_WARNING:
|
||||
case E_RECOVERABLE_ERROR:
|
||||
$level = 'Warning';
|
||||
break;
|
||||
|
||||
case E_NOTICE:
|
||||
case E_USER_NOTICE:
|
||||
$level = 'Notice';
|
||||
break;
|
||||
|
||||
case E_STRICT:
|
||||
$level = 'Strict';
|
||||
break;
|
||||
|
||||
case E_DEPRECATED:
|
||||
case E_USER_DEPRECATED:
|
||||
$level = 'Deprecated';
|
||||
break;
|
||||
|
||||
default:
|
||||
$level = 'Type Unknown';
|
||||
break;
|
||||
}
|
||||
|
||||
echo \View::make('errors.exception')->with('level', $level)
|
||||
->with('message', $e->getMessage())
|
||||
->with('file', $e->getFile())
|
||||
->with('line', $e->getLine());
|
||||
|
||||
exit;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -46,12 +46,16 @@ class Http
|
|||
|
||||
public static function getCurrentUrl()
|
||||
{
|
||||
$url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? "https://" : "http://";
|
||||
$url .= $_SERVER["SERVER_NAME"];
|
||||
$url .= ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
|
||||
$url .= $_SERVER["REQUEST_URI"];
|
||||
return self::getBaseUrl().$_SERVER["REQUEST_URI"];
|
||||
}
|
||||
|
||||
return $url;
|
||||
public static function getBaseUrl()
|
||||
{
|
||||
$base_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? "https://" : "http://";
|
||||
$base_url .= $_SERVER["SERVER_NAME"];
|
||||
$base_url .= ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
|
||||
|
||||
return $base_url;
|
||||
}
|
||||
|
||||
public static function abort($code, $msg = "Something happened.", $is_json = false)
|
||||
|
|
|
|||
|
|
@ -23,8 +23,15 @@ if ($_ENV['APP_DEBUG'] !== "false") {
|
|||
new \Whoops\Handler\PrettyPageHandler : new \Whoops\Handler\PlainTextHandler;
|
||||
$whoops->pushHandler($handler);
|
||||
$whoops->register();
|
||||
} else {
|
||||
set_error_handler(function ($errno, $errstr, $errfile, $errline) {
|
||||
Exceptions\ExceptionHandler::handler(
|
||||
new \ErrorException($errstr, $errno, $errno, $errfile, $errline)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// set aliases for App\Services
|
||||
$services = require BASE_DIR.'/config/services.php';
|
||||
foreach ($services as $facade => $class) {
|
||||
class_alias($class, $facade);
|
||||
|
|
@ -51,6 +58,7 @@ $capsule->bootEloquent();
|
|||
|
||||
session_start();
|
||||
|
||||
// require route config
|
||||
\Pecee\SimpleRouter\SimpleRouter::group([
|
||||
'exceptionHandler' => 'App\Exceptions\RouterExceptionHandler'
|
||||
], function() {
|
||||
|
|
|
|||
10
resources/views/errors/e.tpl
Normal file
10
resources/views/errors/e.tpl
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
@extends('errors.general')
|
||||
|
||||
@section('title', '出现错误')
|
||||
|
||||
@section('content')
|
||||
<h1>{{ 出现了一些错误:}}</h1>
|
||||
|
||||
<p>错误码: {{ $code }}</p>
|
||||
<p>详细信息:{{ $message }}</p>
|
||||
@endsection
|
||||
|
|
@ -3,8 +3,10 @@
|
|||
@section('title', '出现错误')
|
||||
|
||||
@section('content')
|
||||
<h1>出现了一些错误:</h1>
|
||||
<h1>{{ $level }}: 出现了一些错误</h1>
|
||||
|
||||
<p>错误码: {{ $code }}</p>
|
||||
<p>详细信息:{{ $message }}</p>
|
||||
|
||||
<p>文件位置:<b>{{ $file }}: {{ $line }}</b></p>
|
||||
|
||||
@endsection
|
||||
|
|
|
|||
|
|
@ -5,8 +5,7 @@
|
|||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="robots" content="noindex,nofollow" />
|
||||
<title>@yield('title') - Blessing Skin Server</title>
|
||||
<link rel="stylesheet" type="text/css" href="https://cdn.moefont.com/fonts/css?family=Ubuntu">
|
||||
<link rel="stylesheet" type="text/css" href="https://work.prinzeugen.net/font/Minecraft.css">
|
||||
<link rel="stylesheet" type="text/css" href="{{ \Http::getBaseUrl() }}/assets/dist/css/style.css">
|
||||
</head>
|
||||
|
||||
<body class="container">
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user