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