|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Gameap\Exceptions; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; |
|
6
|
|
|
use Illuminate\Http\Response; |
|
7
|
|
|
|
|
8
|
|
|
class Handler extends ExceptionHandler |
|
9
|
|
|
{ |
|
10
|
|
|
private const MAP_EXCEPTION_HTTP_CODE = [ |
|
11
|
|
|
\Gameap\Exceptions\GdaemonAPI\InvalidApiKeyException::class => Response::HTTP_UNAUTHORIZED, |
|
12
|
|
|
\Gameap\Exceptions\GdaemonAPI\InvalidTokenExeption::class => Response::HTTP_UNAUTHORIZED, |
|
13
|
|
|
\Gameap\Exceptions\Repositories\RecordExistExceptions::class => Response::HTTP_UNPROCESSABLE_ENTITY, |
|
14
|
|
|
\Gameap\Exceptions\Repositories\RepositoryValidationException::class => Response::HTTP_BAD_REQUEST, |
|
15
|
|
|
\Illuminate\Validation\ValidationException::class => Response::HTTP_UNPROCESSABLE_ENTITY, |
|
16
|
|
|
]; |
|
17
|
|
|
|
|
18
|
|
|
public function render($request, \Throwable $exception) |
|
19
|
|
|
{ |
|
20
|
|
|
if ($request->expectsJson() || $request->isJson()) { |
|
21
|
|
|
return $this->renderJson($request, $exception); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
if ($exception instanceof \Gameap\Exceptions\GdaemonAPI\InvalidSetupTokenExeption) { |
|
25
|
|
|
if (app()->has('debugbar')) { |
|
26
|
|
|
app('debugbar')->disable(); |
|
|
|
|
|
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
// Return bash |
|
30
|
|
|
return response()->make('echo "' . $exception->getMessage() . '"', 401); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
return parent::render($request, $exception); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
private function renderJson($request, \Throwable $exception) |
|
37
|
|
|
{ |
|
38
|
|
|
foreach (self::MAP_EXCEPTION_HTTP_CODE as $instance => $httpCode) { |
|
39
|
27 |
|
if ($exception instanceof $instance) { |
|
40
|
|
|
return response()->json([ |
|
41
|
27 |
|
'message' => $exception->getMessage(), |
|
42
|
27 |
|
'http_code' => $httpCode, |
|
43
|
|
|
], $httpCode); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
return parent::render($request, $exception); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.