| <?php |
| |
| namespace App\Exceptions; |
| |
| use App\Api\Helpers\ExceptionReport; |
| use App\Api\Utils\Util; |
| use Illuminate\Auth\Access\AuthorizationException; |
| use Illuminate\Auth\AuthenticationException; |
| use Illuminate\Database\Eloquent\ModelNotFoundException; |
| use Illuminate\Database\QueryException; |
| use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; |
| use Illuminate\Support\Facades\Log; |
| use Illuminate\Validation\ValidationException; |
| use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; |
| use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
| use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; |
| use Throwable; |
| |
| class Handler extends ExceptionHandler |
| { |
| |
| |
| |
| |
| |
| protected $dontReport = [ |
| |
| |
| |
| ]; |
| |
| |
| |
| |
| |
| |
| protected $dontFlash = [ |
| 'current_password', |
| 'password', |
| 'password_confirmation', |
| ]; |
| |
| |
| |
| |
| |
| |
| public function register() |
| { |
| $this->reportable(function (Throwable $e) { |
| |
| }); |
| |
| $this->renderable(function (ValidationException $e, $request) { |
| return response()->json(Util::JsonDataArr(400,$e->getMessage())); |
| }); |
| |
| $this->renderable(function (AuthenticationException $e, $request) { |
| Log::error($e->getMessage(), ['AuthenticationException']); |
| return response()->json($this->getMessageError(AuthenticationException::class)); |
| }); |
| |
| $this->renderable(function (ModelNotFoundException $e, $request) { |
| return response()->json($this->getMessageError(ModelNotFoundException::class)); |
| }); |
| |
| $this->renderable(function (AuthorizationException $e, $request) { |
| return response()->json($this->getMessageError(AuthorizationException::class)); |
| }); |
| |
| $this->renderable(function (UnauthorizedHttpException $e, $request) { |
| return response()->json($this->getMessageError(UnauthorizedHttpException::class)); |
| }); |
| |
| $this->renderable(function (NotFoundHttpException $e, $request) { |
| return response()->json($this->getMessageError(NotFoundHttpException::class)); |
| }); |
| |
| $this->renderable(function (MethodNotAllowedHttpException $e, $request) { |
| return response()->json($this->getMessageError(MethodNotAllowedHttpException::class)); |
| }); |
| |
| $this->renderable(function (QueryException $e, $request) { |
| return response()->json($this->getMessageError(QueryException::class)); |
| }); |
| } |
| |
| private function getMessageError($class) |
| { |
| $message = ExceptionReport::$doReportOther[$class]; |
| return Util::JsonDataArr(400, $message[0]); |
| |
| } |
| } |