Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Docs) Change $response->status() to $response->getStatusCode() in error-handling documentation #267

Open
chrislow opened this issue Nov 18, 2022 · 0 comments

Comments

@chrislow
Copy link

I found out, that running phpstan threw an error at this part of the error-handling code documented here. I added a pull request to change the documented error-handling code. Feel free to merge it.

Further explanation:

# The command i ran
vendor/bin/phpstan analyse app -c ./vendor/nunomaduro/larastan/extension.neon  --level=4 --no-progress --memory-limit=2G

# The errors i got: 
------ ---------------------------------------------------------------------------------------------------------------------
 Line   Exceptions/Handler.php
------ ---------------------------------------------------------------------------------------------------------------------
 63     Call to an undefined method Symfony\Component\HttpFoundation\Response::status().
 64     Call to an undefined method Symfony\Component\HttpFoundation\Response::status().
 64     Method App\Exceptions\Handler::render() should return Illuminate\Http\RedirectResponse|Inertia\Response but returns
        Symfony\Component\HttpFoundation\Response.
 66     Call to an undefined method Symfony\Component\HttpFoundation\Response::status().
 67     Call to an undefined method Symfony\Component\HttpFoundation\Response::status().
 73     Method App\Exceptions\Handler::render() should return Illuminate\Http\RedirectResponse|Inertia\Response but returns
        Symfony\Component\HttpFoundation\Response.
------ ---------------------------------------------------------------------------------------------------------------------

Change $response->status() to $response->getStatusCode()

    public function render($request, Throwable $e)
    {
        $response = parent::render($request, $e);

        if (!app()->environment(['local', 'testing']) && in_array($response->getStatusCode(), [500, 503, 404, 403])) {
            return Inertia::render('Error', ['status' => $response->getStatusCode()])
                ->toResponse($request)
                ->setStatusCode($response->getStatusCode());
        } else if ($response->getStatusCode() === 419) {
            return back()->with([
                'message' => 'The page expired, please try again.',
            ]);
        }

        return $response;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant