-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHandler.php
More file actions
78 lines (69 loc) · 2.36 KB
/
Handler.php
File metadata and controls
78 lines (69 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
namespace App\Exceptions;
use App\Library\Syslog;
use Exception;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
class Handler extends ExceptionHandler
{
/**
* A list of the exception types that should not be reported.
*
* @var array
*/
protected $dontReport = [
HttpException::class,
ModelNotFoundException::class,
];
/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $e
* @return void
*/
public function report(Exception $e)
{
return parent::report($e);
}
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
if ($e instanceof ModelNotFoundException) {
$e = new NotFoundHttpException($e->getMessage(), $e);
}
// 微信用户屏蔽公众号消息
if ($e->getCode() === 48002) {
exit;
}
if ($e instanceof MethodNotAllowedHttpException) {
Syslog::logger('METHOD_NOT_FOUND')->addWarning('METHOD_NOT_FOUND', [$e]);
if (!env('APP_DEBUG')) {
return response()->view('errors.error', ['title' => 'Method Not Found', 'desc' => ''], 200);
}
}
// 404
if ($e instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException) {
Syslog::logger('WEB')->addWarning('REQUEST_ERROR_404', [$e]);
if (!env('APP_DEBUG')) {
return response()->view('errors.error', ['title' => '404', 'desc' => '页面找不到了'], 404);
}
} else {
Syslog::logger('WEB')->addCritical('REQUEST_ERROR_500', [$e]);
if (!env('APP_DEBUG')) {
return response()->view('errors.error', ['title' => '服务器错误,请稍后访问', 'desc' => ''], 500);
}
}
return parent::render($request, $e);
}
}