diff --git a/.env.example b/.env.example index 21e860aa..4cee6347 100644 --- a/.env.example +++ b/.env.example @@ -60,3 +60,5 @@ APP_TIMEZONE=UTC APP_LANG=en APP_LOG=daily SECURE_SESSION_COOKIE=true + +SLACK_WEBHOOK_URL= diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 971523ba..1da163fb 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -2,6 +2,7 @@ namespace App\Exceptions; +use App; use Exception; use Illuminate\Support\Facades\Route; use Illuminate\Session\TokenMismatchException; @@ -18,7 +19,7 @@ class Handler extends ExceptionHandler * @var array */ protected $dontReport = [ - // + \Symfony\Component\HttpKernel\Exception\HttpException::class, ]; /** @@ -41,6 +42,32 @@ class Handler extends ExceptionHandler */ public function report(Exception $exception) { + $guzzle = new \GuzzleHttp\Client([ + 'headers' => [ + 'Content-Type' => 'application/json', + ], + ]); + + $guzzle->post( + env('SLACK_WEBHOOK_URL'), + [ + 'body' => json_encode([ + 'attachments' => [[ + 'fallback' => 'There was an exception.', + 'pretext' => 'There was an exception.', + 'color' => '#d00000', + 'author_name' => App::environment(), + 'author_link' => config('app.url'), + 'fields' => [[ + 'title' => get_class($exception) ?? 'Unkown Exception', + 'value' => $exception->getMessage() ?? '', + ]], + 'ts' => time(), + ]], + ]), + ] + ); + parent::report($exception); }