Last active
June 11, 2020 07:12
-
-
Save sajt/740c3704ef32dbcbba7110e15c7584c0 to your computer and use it in GitHub Desktop.
Revisions
-
sajt revised this gist
Jun 11, 2020 . 1 changed file with 38 additions and 38 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,41 +1,41 @@ /** * Render an exception into an HTTP response. * * @param \Illuminate\Http\Request $request * @param \Exception $exception * @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse */ public function render($request, Exception $exception) { if (env('APP_DEBUG')) { return parent::render($request, $exception); } $status = Response::HTTP_INTERNAL_SERVER_ERROR; if ($exception instanceof HttpResponseException) { $status = Response::HTTP_INTERNAL_SERVER_ERROR; } elseif ($exception instanceof ModelNotFoundException) { $status = 200; // Ez azrt 200, mert különben nem megy át a json. } elseif ($exception instanceof MethodNotAllowedHttpException) { $status = Response::HTTP_METHOD_NOT_ALLOWED; $exception = new MethodNotAllowedHttpException([], 'HTTP_METHOD_NOT_ALLOWED', $exception); } elseif ($exception instanceof NotFoundHttpException) { $status = $exception->getStatusCode(); //$exception = new NotFoundHttpException('HTTP_NOT_FOUND', $exception); } elseif ($exception instanceof AuthorizationException) { $status = Response::HTTP_FORBIDDEN; $exception = new AuthorizationException('HTTP_FORBIDDEN', $status); } elseif ($exception instanceof \Dotenv\Exception\ValidationException && $exception->getResponse()) { $status = Response::HTTP_BAD_REQUEST; $exception = new \Dotenv\Exception\ValidationException('HTTP_BAD_REQUEST', $status, $exception); } elseif ($exception) { $status = 200; // $exception = new HttpException($status, 'HTTP_INTERNAL_SERVER_ERROR'); } return response()->json([ 'success' => false, 'status' => $status, 'message' => $exception->getMessage() ], $status); // Itt mindig 200-at kell visszaadni } -
sajt revised this gist
Jun 11, 2020 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -33,8 +33,6 @@ $status = 200; // $exception = new HttpException($status, 'HTTP_INTERNAL_SERVER_ERROR'); } return response()->json([ 'success' => false, 'status' => $status, -
sajt created this gist
Jun 11, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ /** * Render an exception into an HTTP response. * * @param \Illuminate\Http\Request $request * @param \Exception $exception * @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse */ public function render($request, Exception $exception) { if (env('APP_DEBUG')) { return parent::render($request, $exception); } $status = Response::HTTP_INTERNAL_SERVER_ERROR; if ($exception instanceof HttpResponseException) { $status = Response::HTTP_INTERNAL_SERVER_ERROR; } elseif ($exception instanceof ModelNotFoundException) { $status = 200; // Ez azrt 200, mert különben nem megy át a json. } elseif ($exception instanceof MethodNotAllowedHttpException) { $status = Response::HTTP_METHOD_NOT_ALLOWED; $exception = new MethodNotAllowedHttpException([], 'HTTP_METHOD_NOT_ALLOWED', $exception); } elseif ($exception instanceof NotFoundHttpException) { $status = $exception->getStatusCode(); //$exception = new NotFoundHttpException('HTTP_NOT_FOUND', $exception); } elseif ($exception instanceof AuthorizationException) { $status = Response::HTTP_FORBIDDEN; $exception = new AuthorizationException('HTTP_FORBIDDEN', $status); } elseif ($exception instanceof \Dotenv\Exception\ValidationException && $exception->getResponse()) { $status = Response::HTTP_BAD_REQUEST; $exception = new \Dotenv\Exception\ValidationException('HTTP_BAD_REQUEST', $status, $exception); } elseif ($exception) { $status = 200; // $exception = new HttpException($status, 'HTTP_INTERNAL_SERVER_ERROR'); } // dump($exception); // return "hello"; return response()->json([ 'success' => false, 'status' => $status, 'message' => $exception->getMessage() ], $status); // Itt mindig 200-at kell visszaadni }