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

Email or Log Exceptions #133

Closed
DarkAxi0m opened this issue Feb 13, 2014 · 17 comments
Closed

Email or Log Exceptions #133

DarkAxi0m opened this issue Feb 13, 2014 · 17 comments

Comments

@DarkAxi0m
Copy link

Just found this and i was thinking It would be nice to have on a production machine, that an Exception handled by
-just showing an Error page (500 or similar) to the user
-then log the exception locally
-or email something like the PrettyPageHandler output to an Email address.

@denis-sokolov
Copy link
Collaborator

Showing an error page to the user can't really be our responsibility.
Most often that error should fit the design of your site,
and should not include any technical information.
So really, all you need is:

$run->pushHandler(function($exception, $inspector, $run){
    http_response_code(500);
    echo file_get_contents('my500.html');
});

For logging errors we could have created an LoggingHandler of some sorts, but PHP has error logging built-in, so just use that.

Finally, sending a pretty email is a good idea, I've added it to the requested features list.

@mnpenner
Copy link

👍 I would like a pretty email generator.

@lighterfluid
Copy link

👍 EmailHandler would be great.

@GrahamCampbell
Copy link
Contributor

I think this is something that would be better handled by each user, and not by whoops.

For example, laravel users may which to use the laravel mail component.

@mnpenner
Copy link

mnpenner commented Nov 3, 2014

@GrahamCampbell Even if we used the Laravel mail component, it would be nice of Whoops produced the pretty HTML for us and then gave us a callback so that we can send it.

@GrahamCampbell
Copy link
Contributor

Yeh, that would be nice.

@mfutselaar
Copy link

If I could star @mnbayazit's reply, I would have starred it over a million times.

I'm currently in the process of writing a custom error handler for our projects, and would like to send the pretty html as an attachment to our ticketing system. A callback like that would be most excellent!

@denis-sokolov
Copy link
Collaborator

I fully agree and would support a pull request implementing that.

@avindra
Copy link

avindra commented May 26, 2016

Can we reopen this?

Currently in our project we are doing:

$this->whoops->pushHandler(function($exception, $inspector, $run) {
    // Truncated.... we email our error here
    return \Whoops\Handler\Handler::DONE;
});

Are there any code samples for hooking into the pretty page handler and:

  1. Keeping the original behavior of PrettyPageHandler
  2. Emailing the output of PrettyPageHandler in addition

@avindra
Copy link

avindra commented May 26, 2016

Given that there are many ways to send emails in PHP (in my team's project, we use PHPMailer, and I'm sure others are using any number of other methods)....

I think providing some means of hooking into the response from PrettyPageHandler so we can email it out as necessary would be ideal.

@denis-sokolov
Copy link
Collaborator

It’s not an issue, it’s a feature request. Until someone contributes the feature in a PR there’s no value in keeping the issue open. A PR is welcome, albeit for this feature a discussion in advance would be appreciated.

@avindra
Copy link

avindra commented May 26, 2016

@denis-sokolov : Perhaps open this and label it a feature request? Lots of projects follow this pattern as it increases transparency.

I had to do a bit of digging to find this page: https://github.com/filp/whoops/wiki/Possible-features-to-add

@denis-sokolov
Copy link
Collaborator

It’s a matter of preference. In Whoops not keeping tens of feature request allows us to keep track of actual issues.

@Julusian
Copy link

For anyone else interested in this, I managed it as follows:

use Whoops\Run as Whoops;
use Whoops\Handler\PrettyPageHandler as Handler;

$whoops = new Whoops();
$whoops->allowQuit(false);
$whoops->writeToOutput(false);
$whoops->pushHandler(new Handler());
$body = $whoops->handleException($this->exception);

$body contains the html page as a string, so can be emailed or used however you wish

@reeperbahnause
Copy link

I'm using Slim and I have no idea how to get the PrettyPageHandler body.
I see a few ways like extending the Handler or exchange the middleware but I guess there is an easier way of getting the pretty page. If I would have access to the body emailing it wouldn't be a problem.
Could anyone help me with that?

@staabm
Copy link
Contributor

staabm commented Apr 24, 2017

see e.g. https://github.com/redaxo/redaxo/blob/b4da95c603024e660d5686351797e53c96f11a42/redaxo/src/core/lib/error_handler.php#L62-L74 in which we retrieve the contents from the handler as a string.

(its the same code like the one above in the comment though)

@iovino
Copy link

iovino commented May 7, 2017

For anyone that wants to use Julusian's approach in a CLI application like I am, you'll need to set handleUnconditionally to true.

$handler->handleUnconditionally(true);

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