Handler.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace App\Exceptions;
  3. use App\Notification\DingDingRobot;
  4. use App\Notification\TelegramBot;
  5. use Exception;
  6. use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
  7. use Illuminate\Support\Facades\Config;
  8. use Illuminate\Support\Facades\Log;
  9. use Illuminate\Support\Facades\Request;
  10. class Handler extends ExceptionHandler
  11. {
  12. /**
  13. * A list of the exception types that are not reported.
  14. *
  15. * @var array
  16. */
  17. protected $dontReport = [
  18. //
  19. ];
  20. /**
  21. * A list of the inputs that are never flashed for validation exceptions.
  22. *
  23. * @var array
  24. */
  25. protected $dontFlash = [
  26. 'password',
  27. 'password_confirmation',
  28. ];
  29. /**
  30. * Report or log an exception.
  31. *
  32. * @param \Exception $exception
  33. * @return void
  34. */
  35. public function report(Exception $exception)
  36. {
  37. if (false&&$this->shouldReport($exception)) {
  38. Log::info('Exception Happen', [
  39. 'error'=>$exception->getMessage(),
  40. 'url' => Request::url(),
  41. 'params' => Request::all(),
  42. 'trace' => $exception->getTraceAsString()
  43. ]);
  44. $env = env('APP_ENV');
  45. TelegramBot::getDefault()->sendProgramNotify("api",
  46. $exception->getMessage() . "\n" .
  47. '#### url:' . Request::getRequestUri() . "\n" .
  48. '#### params:' . json_encode(Request::all()) . "\n" .
  49. '#### ' . $exception->getTraceAsString() . "\n"
  50. );
  51. }
  52. parent::report($exception);
  53. }
  54. /**
  55. * Render an exception into an HTTP response.
  56. *
  57. * @param \Illuminate\Http\Request $request
  58. * @param \Exception $exception
  59. * @return \Illuminate\Http\Response
  60. */
  61. public function render($request, Exception $exception)
  62. {
  63. // if (Config::get('app.debug') === false) {
  64. // if ($request->ajax()) {
  65. // $message = $exception->getMessage();
  66. // $line = $exception->getLine();
  67. // $file = $exception->getFile();
  68. // $code = $exception->getCode();
  69. // return response()->json(['code' => 500, 'msg' => '请求发生错误!', 'data' => [
  70. // 'code' => $code,
  71. // 'line' => $line,
  72. // 'file' => $file,
  73. // 'message' => $message,
  74. // ]]);
  75. // } else {
  76. // return response()->view('base.404');
  77. // }
  78. // }
  79. return parent::render($request, $exception);
  80. }
  81. }