Skip to content

Instantly share code, notes, and snippets.

@sajt
Last active June 11, 2020 07:12
Show Gist options
  • Save sajt/740c3704ef32dbcbba7110e15c7584c0 to your computer and use it in GitHub Desktop.
Save sajt/740c3704ef32dbcbba7110e15c7584c0 to your computer and use it in GitHub Desktop.

Revisions

  1. sajt revised this gist Jun 11, 2020. 1 changed file with 38 additions and 38 deletions.
    76 changes: 38 additions & 38 deletions Exception
    Original 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);
    }
    * 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;
    $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
    }
    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
    }
  2. sajt revised this gist Jun 11, 2020. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions Exception
    Original file line number Diff line number Diff line change
    @@ -33,8 +33,6 @@
    $status = 200;
    // $exception = new HttpException($status, 'HTTP_INTERNAL_SERVER_ERROR');
    }
    // dump($exception);
    // return "hello";
    return response()->json([
    'success' => false,
    'status' => $status,
  3. sajt created this gist Jun 11, 2020.
    43 changes: 43 additions & 0 deletions Exception
    Original 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
    }