, \Psr\Log\LogLevel::*> */ protected $levels = [ // ]; /** * A list of the exception types that are not reported. * * @var array> */ protected $dontReport = [ // ]; /** * A list of the inputs that are never flashed for validation exceptions. * * @var array */ protected $dontFlash = [ 'current_password', 'password', 'password_confirmation', ]; /** * Register the exception handling callbacks for the application. * * @return void */ public function register() { $this->reportable(function (Throwable $e) { // }); } public function render($request, Throwable $exception) { if ($request->wantsJson()) { if ($exception instanceof AuthenticationException) { return response()->json([ 'status' => 'error', 'statusCode' => Response::HTTP_UNAUTHORIZED, 'message' => 'Unauthenticated', 'errors' => [ 'Unauthenticated' ] ], Response::HTTP_UNAUTHORIZED); } if ($exception instanceof AuthorizationException) { return response()->json([ 'status' => 'error', 'statusCode' => Response::HTTP_FORBIDDEN, 'message' => 'This action is unauthorized.', 'errors' => [ 'This action is unauthorized.' ] ], Response::HTTP_FORBIDDEN); } if ($exception instanceof NotFoundHttpException) { return response()->json([ 'status' => 'error', 'statusCode' => Response::HTTP_NOT_FOUND, 'message' => 'Route Not Found', 'errors' => [ 'Route Not Found' ] ], Response::HTTP_NOT_FOUND); } if ($exception instanceof ModelNotFoundException) { return response()->json([ 'status' => 'error', 'statusCode' => Response::HTTP_NOT_FOUND, 'message' => 'Record for ' . str_replace('App', '', str_replace('\\Models\\', '', $exception->getModel())) . ' not found', 'errors' => [ 'Record for ' . str_replace('App', '', str_replace('\\Models\\', '', $exception->getModel())) . ' not found' ] ], Response::HTTP_NOT_FOUND); } if ($exception instanceof ValidationException) { return response()->json([ 'status' => 'error', 'statusCode' => Response::HTTP_UNPROCESSABLE_ENTITY, 'message' => 'The given data was invalid.', 'errors' => collect($exception->errors())->flatten() ], Response::HTTP_UNPROCESSABLE_ENTITY); } } return parent::render($request, $exception); } }