(string)$exception->getMessage(), 'status_code' => 400, ]; if ($exception instanceof HttpException) { $response['message'] = Response::$statusTexts[$exception->getStatusCode()]; $response['status_code'] = $exception->getStatusCode(); } else if ($exception instanceof ModelNotFoundException) { $response['message'] = Response::$statusTexts[Response::HTTP_NOT_FOUND]; $response['status_code'] = Response::HTTP_NOT_FOUND; } if ($this->isDebugMode()) { $response['debug'] = [ 'exception' => get_class($exception), 'trace' => $exception->getTrace() ]; // return parent::render($request, $exception); } return response()->json($response, $response['status_code']); } return parent::render($request, $exception); } /** * Determine if the application is in debug mode. * * @return Boolean */ public function isDebugMode() { return (boolean) env('APP_DEBUG'); } }