1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMartins\JsonHandler; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\App; |
|
|
|
|
6
|
|
|
use GuzzleHttp\Exception\ClientException; |
|
|
|
|
7
|
|
|
|
8
|
|
|
trait ClientHandler |
9
|
|
|
{ |
10
|
|
|
public function clientException(ClientException $exception) |
11
|
|
|
{ |
12
|
|
|
$statusCode = 500; |
13
|
|
|
$title = 'client_exception'; |
14
|
|
|
$code = config($this->configFile.'codes.client.default'); |
|
|
|
|
15
|
|
|
$detail = __('exception::exceptions.client.unavailable'); |
|
|
|
|
16
|
|
|
|
17
|
|
|
$requestHost = $exception->getRequest()->getUri()->getHost(); |
18
|
|
|
$clientCausers = $this->clientExceptionCausers(); |
19
|
|
|
|
20
|
|
|
if ($clientCausers->isPagarme($requestHost)) { |
21
|
|
|
$code = config('json-exception-handler.codes.client.pagarme') ?? 'pagarme'; |
22
|
|
|
} elseif ($clientCausers->isMailgun($requestHost)) { |
23
|
|
|
$code = config('json-exception-handler.codes.client.mailgun') ?? 'mailgun'; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
if (App::environment('production')) { |
27
|
|
|
$detail = $detail.' #'.$code; |
28
|
|
|
} else { |
29
|
|
|
$response = $exception->getResponse(); |
30
|
|
|
$detail = json_decode($response->getBody())->message; |
31
|
|
|
$statusCode = $response->getStatusCode(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
$error = [[ |
35
|
|
|
'status' => $statusCode, |
36
|
|
|
'code' => $code, |
37
|
|
|
'source' => ['pointer' => $exception->getFile().':'.$exception->getLine()], |
38
|
|
|
'title' => $title, |
39
|
|
|
'detail' => $detail, |
40
|
|
|
]]; |
41
|
|
|
|
42
|
|
|
$this->jsonApiResponse->setStatus($statusCode); |
|
|
|
|
43
|
|
|
$this->jsonApiResponse->setErrors($error); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function clientExceptionCausers() |
47
|
|
|
{ |
48
|
|
|
return new class() { |
49
|
|
|
const PAGARME_HOST = 'api.pagar.me'; |
50
|
|
|
|
51
|
|
|
const MAILGUN_HOST = 'api.mailgun.net'; |
52
|
|
|
|
53
|
|
|
public function isPagarme($host) |
54
|
|
|
{ |
55
|
|
|
return self::PAGARME_HOST == $host; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function isMailgun($host) |
59
|
|
|
{ |
60
|
|
|
return self::MAILGUN_HOST == $host; |
61
|
|
|
} |
62
|
|
|
}; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths