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

Throwing arbitrary error codes #2164

Closed
Perlkonig opened this issue Aug 30, 2018 · 4 comments
Closed

Throwing arbitrary error codes #2164

Perlkonig opened this issue Aug 30, 2018 · 4 comments
Labels

Comments

@Perlkonig
Copy link
Contributor

From within the Grav core code, I want to be able to emit an arbitrary HTTP status code. I'm told I should be able to do something like throw new \RuntimeException("Should be a 406", 406);, but that doesn't actually work.

I want to make changes to Grav\Common\Twig\Twig.php, specifically the processSite function. So I try the following:

public function processSite($format = null, array $vars = [])
{
    throw new \RuntimeException("Should be a 406", 406);
    ...
}

What I get is an error page with a status header of 500. I've tried tracing back where the status code gets set, but I can't find it. I would appreciate any assistance in understanding the lifecycle here. The earliest I can find is the end of index.php. But I can't find any code that triggers onFatalException.

@mahagr
Copy link
Member

mahagr commented Sep 5, 2018

FYI: This is something that is limited by Whoops -- it will always use 500 errors in its responses. Overriding error handlers (especially for JSON) may be helpful, but requires some core changes.

@Perlkonig
Copy link
Contributor Author

Well this gives me a place to look, at least. Whoops\Run has a sendHttpCode function. I guess I'll start from there.

So does this mean that existing calls like this and this in Grav core aren't actually working either?

@mahagr
Copy link
Member

mahagr commented Sep 6, 2018

Some of the exceptions are catched by Grav or plugins so they work.

@Perlkonig
Copy link
Contributor Author

PR submitted.

@mahagr mahagr closed this as completed Dec 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants