anlutro / l4-smart-errors
Smart error reporting for Laravel.
Installs: 15 296
Dependents: 0
Suggesters: 0
Security: 0
Stars: 65
Watchers: 3
Forks: 13
Open Issues: 2
Requires
- php: >=5.4.0
- laravel/framework: ~4.1
- xethron/l4-to-string: 1.0.*
Requires (Dev)
- anlutro/l4-testing: 0.2.*
- laravel/laravel: ~4.1
- mockery/mockery: 0.9.*
- dev-master
- 2.5.1
- 2.5.0
- 2.4.12
- 2.4.11
- 2.4.10
- 2.4.9
- 2.4.8
- 2.4.7
- 2.4.6
- 2.4.5
- 2.4.4
- 2.4.3
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.7
- 2.3.6
- 2.3.5
- 2.3.4
- 2.3.3
- 2.3.2
- 2.3.1
- 2.3.0
- 2.2.1
- 2.2.0
- 2.1.0
- 2.0.0
- 1.6.1
- 1.6.0
- 1.5.1
- 1.5.0
- 1.4.7
- 1.4.6
- 1.4.5
- 1.4.4
- 1.4.3
- 1.4.2
- 1.4.1
- 1.4.0
- 1.3.0
- 1.2.1
- 1.2.0
- 1.1.0
- 1.0.0
- dev-develop
- dev-laravel5
This package is auto-updated.
Last update: 2024-10-24 09:10:26 UTC
README
Small system for showing a very generic error message to your end-users while sending an email to yourself with all relevant information about the exception.
- Uncaught exceptions send an email with detailed information (referrer, route name/action, any input given and more)
- 404 errors are written in the log as warnings with the URL accessed + referrer
- Alert-level log events are sent via email (since 1.3)
NOTE: Laravel 5 is not supported. See this issue.
Installation
To install, run composer require anlutro/l4-smart-errors
. This will pick the most appropriate version and add it to your composer.json
.
IMPORTANT: Upgrading from 2.1
Behaviour has changed in 2.2 in a slightly backwards incompatible way. If 'error-view' or 'missing-view' in the config file is set to null, a view response is not returned at all from the error/404 handler. This is in order to let users add their own App::error / App::missing handlers that returns a view with custom data, instead of being forced into using a view composer if you want to use a custom view which requires specific variables to be defined.
To keep behaviour as is in 2.1, make sure the config file is published, then change your config.php file to include the following lines:
'error-view' => 'smarterror::generic',
'missing-view' => 'smarterror::missing',
Usage
When the package has been downloaded, add the following to the list of service providers in app/config/app.php
:
'anlutro\L4SmartErrors\L4SmartErrorsServiceProvider',
Run php artisan config:publish anlutro/l4-smart-errors
and open the config file that has been generated. Modify it to your needs. Copy the lang and/or views directories from the vendor directory if you want some templates to work with.
Remove any App::error
and App::missing
you may have in your application to prevent conflicts. If you want to handle specific types of exceptions yourself, you can add App::error
closures with those specific exceptions as arguments. Exceptions handled using App::error
will not be e-mailed or logged by this package.
Exception email reports
Exceptions are e-mailed as long as app.debug
is false, and the dev-email
key is filled out in the package config file. Make sure that your mail.php
config file is correct - test it with a regular Mail::send()
. If your mailer is incorrectly configured, you may get a blank "error in exception handler" screen upon errors.
Email reports are throttled, so that the exact same exception won't be sent over and over again. By default, the threshold for when an identical exception should be emailed again is 10 minutes. This can be configured with the throttle-age
config key.
Note that emails are not sent when app.debug
is true.
End-user responses
For any uncaught/unhandled exceptions, the package will return a generic error response to your end users unless app.debug
is true. If you get this generic response while developing, you might not be setting the correct environment - check your bootstrap/start.php
.
You can configure which view is displayed with the error-view
, missing-view
and csrf-view
config values. If you set these to null
, the package will not return a generic response to your end users, allowing you to implement your own, as shown in this example:
// app/start/global.php App::pushError(function($exception) { if (App::runningInConsole() || Config::get('app.debug')) return; return Response::view('my-error-view', [...], 500); });
Using pushError
instead of error
makes sure that it's pushed to the end of the exception handler stack, giving the package's error handler priority over yours.
Localizing the response
This repositories' languages and translations are sporadically updated at best. To ensure that your translation is always up-to-date and/or if you want to manage your translation yourself, run the following commands.
mkdir -p ./app/lang/packages/MYLOCALE/smarterror`
cp ./vendor/anlutro/laravel-4-smart-errors/src/lang/en/*.php ./app/lang/packages/MYLOCALE/smarterror
You can also copy from a different locale than "en".
If your locale is missing, your generic end-user responses will only have placeholder strings. You can make this default to english by putting 'fallback_locale' => 'en',
into app/config/app.php
.
Contribution
I'll accept language files right away without discussion. For anything else, please be descriptive in your pull requests.
Contact
Open an issue on GitHub if you have any problems or suggestions.
License
The contents of this repository is released under the MIT license.