Handler.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace App\Exceptions;
  3. use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
  4. use Illuminate\Support\Facades\Http;
  5. use Throwable;
  6. class Handler extends ExceptionHandler
  7. {
  8. /**
  9. * A list of the exception types that are not reported.
  10. *
  11. * @var array
  12. */
  13. protected $dontReport = [
  14. //
  15. ];
  16. /**
  17. * A list of the inputs that are never flashed for validation exceptions.
  18. *
  19. * @var array
  20. */
  21. protected $dontFlash = [
  22. 'password',
  23. 'password_confirmation',
  24. ];
  25. /**
  26. * Report or log an exception.
  27. *
  28. * @param \Throwable $exception
  29. * @return void
  30. *
  31. * @throws \Exception
  32. */
  33. public function report(Throwable $exception)
  34. {
  35. $this->reportError($exception);
  36. parent::report($exception);
  37. }
  38. /**
  39. * Render an exception into an HTTP response.
  40. *
  41. * @param \Illuminate\Http\Request $request
  42. * @param \Throwable $exception
  43. * @return \Symfony\Component\HttpFoundation\Response
  44. *
  45. * @throws \Throwable
  46. */
  47. public function render($request, Throwable $exception)
  48. {
  49. return parent::render($request, $exception);
  50. }
  51. private function reportError(Throwable $e){
  52. try {
  53. if(!$e->getMessage()){
  54. return;
  55. }
  56. if(strtolower($e->getMessage()) == 'not found'){
  57. //ignore
  58. return;
  59. }
  60. if($e->getMessage()){
  61. $url = config('stag.backendUrl') . '/dev/reportPhpError';
  62. $headers['secret'] = 'superman';
  63. Http::asForm()
  64. ->withHeaders($headers)
  65. ->post($url, [
  66. 'data'=>'FE2: '.$e->getMessage().'URL: '.url()->current(),
  67. 'secret' => 'superman'
  68. ])
  69. ->json();
  70. }
  71. }catch(\Exception $e){
  72. //do nothing
  73. }
  74. }
  75. }