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

Browser gets a 200/OK blank page when default exception handler is registered #280

Closed
jamieburchell opened this issue May 3, 2016 · 6 comments

Comments

@jamieburchell
Copy link

jamieburchell commented May 3, 2016

Using the following code:

$client = new Raven_Client(SENTRY_DSN);
$handler = new Raven_ErrorHandler($client, false, null, SENTRY_ERROR_TYPES);
$handler->registerExceptionHandler();
$handler->registerErrorHandler();
$handler->registerShutdownFunction();

When an uncaught exception is caught by the Raven_Client, the browser receives a 200/OK response and blank page. Commenting out the registerExceptionHandler() line gives the expected 500/Internal Server Error response and stock browser message.

Note in the scenario above, there is no existing exception handler registered.

This may be caused by the fact that the exception is actually caught, I'm looking now to see if I can find out more; it would be handy if the response was 500.

@mitsuhiko
Copy link
Member

Currently raven assumes that a default error handler is set with set_exception_handler which we will invoke. if there is no handler we cannot really fall back to default php handling because php does not expose that functionality. I suppose what we could do is if we see that there is no default handler to approximate the default 500 error response somehow.

@jamieburchell
Copy link
Author

jamieburchell commented May 3, 2016

It's a tricky one; I understand that the SDK should be as unobtrusive as possible and if you start modifying response headers you have to think about what happens if the script is running in a cli environment too, it should probably exit with a 1.

In my use case, I'm trying to integrate this in a CodeIgniter 2.x application sigh which has no concept of exceptions or a default exception handler, hence one isn't registered already.

@dcramer
Copy link
Member

dcramer commented May 8, 2016

@jamieburchell is it something that is easy enough for you to pass in your own handler? I'm not sure if thats the best solution, but potentially you could re-throw from there. We could also try to handle this internally in the SDK as well.

@jamieburchell
Copy link
Author

jamieburchell commented May 8, 2016

To solve this one I've defined a default exception handler before instructing the Raven client to register its own. My handler sends a 500.

I'm thinking if an exception handler hasn't already been defined the Raven client should mimic what would have happened had the client not been used, i.e send a 500 status code. I'm not sure what happens with uncaught exceptions in CLI requests but I'm guessing the exit value is non zero.

@luckydonald
Copy link

luckydonald commented May 29, 2017

@jamieburchell
Because this came up for searching for codeigniter,
I also found andrewryno/codeigniter-raven-php where the logger class got overwritten.

@stayallive
Copy link
Collaborator

We are now rethrowing the exception if not other error handler was set so a 500 error will be returned as "normal".

<?php

ini_set('display_errors', false);

require __DIR__ . '/lib/Raven/Autoloader.php';

Raven_Autoloader::register();

$sentry = new Raven_Client;
$sentry->install();

blablabla();

This will show a correct 500 response instead of a 200.

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

5 participants