azishapidin

Laravel report() method

May 1st, 2018
777
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.03 KB | None | 0 0
  1. /**
  2.  * Report or log an exception.
  3.  *
  4.  * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
  5.  *
  6.  * @param  \Exception  $exception
  7.  * @return void
  8.  */
  9. public function report(Exception $exception)
  10. {
  11.     if (!$this->shouldntReport($exception)) {
  12.         $message = $exception->getMessage() . '(' . $exception->getCode() . ')';
  13.         $message .= ' => ' . $exception->getFile()  . ':' . $exception->getline();
  14.         $data = "payload=" . json_encode(array(
  15.             "channel"       => "#error_notifications",
  16.             "text"          => $message,
  17.             "username"      => 'Pemberi tahu',
  18.             "icon_url"      => 'https://media.giphy.com/media/LF8plQNlgYwnK/giphy.gif'
  19.         ));
  20.        
  21.         $ch = curl_init("WebHook URL");
  22.         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  23.         curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  24.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  25.         $result = curl_exec($ch);
  26.         curl_close($ch);
  27.     }
  28.    
  29.     parent::report($exception);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment