Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Handler
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 register
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 sendExternalAlert
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace App\Exceptions;
4
5use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
6use Throwable;
7use Illuminate\Support\Facades\Log;
8
9class Handler extends ExceptionHandler
10{
11    /**
12     * A list of the exception types that are not reported.
13     *
14     * @var array<int, class-string<Throwable>>
15     */
16    protected $dontReport = [
17        //
18    ];
19
20    /**
21     * A list of the inputs that are never flashed for validation exceptions.
22     *
23     * @var array<int, string>
24     */
25    protected $dontFlash = [
26        'current_password',
27        'password',
28        'password_confirmation',
29    ];
30
31    /**
32     * Register the exception handling callbacks for the application.
33     *
34     * @return void
35     */
36    public function register()
37    {
38        $this->reportable(function (Throwable $e) {
39            //
40            $this->sendExternalAlert($e);
41        });
42    }
43
44    private function sendExternalAlert($e) {
45        if(isset($e->exceptionCode)) {
46            $curl = curl_init();
47
48            curl_setopt_array($curl, array(
49                CURLOPT_URL => 'http://production.monitoring.aiwf.ibvgroup.com/api/set-data-point',
50                CURLOPT_RETURNTRANSFER => true,
51                CURLOPT_TIMEOUT => 5, 
52                CURLOPT_CUSTOMREQUEST => 'POST',
53                CURLOPT_POSTFIELDS => json_encode([
54                    "id" => $e->exceptionCode, 
55                    "value" => 1 
56                ]),
57                CURLOPT_HTTPHEADER => array(
58                    'x-api-key: fwoejgrn254oigifvijpkefdsfbmxdkfbff',
59                    'Content-Type: application/json'
60                ),
61            ));
62
63            curl_exec($curl);
64            curl_close($curl);
65        }
66    }
67}