reportable(function (Throwable $e) { // }); $this->renderable(function (AuthenticationException $e) { return response()->json(fail($e->getMessage(), $e->guards()), 401); }); $this->renderable(function (ValidationException $exception) { $errors = $exception->errors(); $msg = Arr::first(Arr::first($errors)); return response()->json(fail($msg, $errors)); }); $this->renderable(function (NotFoundHttpException $e) { return response()->json(fail('No query result.', request()->all()), 404); }); } /** * Prepare a JSON response for the given exception. * * @param \Illuminate\Http\Request $request * @param \Throwable $e * @return \Illuminate\Http\JsonResponse */ protected function prepareJsonResponse($request, Throwable $e) { $data = $request->all(); if (config('app.debug')) { $msg = $e->getMessage() ?: get_class($e); $data['trace'] = $e->getTraceAsString(); } else { $msg = 'Server Error'; } return new JsonResponse( fail($msg, $data), $this->isHttpException($e) ? $e->getStatusCode() : 500, $this->isHttpException($e) ? $e->getHeaders() : [], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ); } }