Reputation: 1672
I am developing a project and i would like to have a notification system especially for the "first days of live" - to receive an email everytime an exception is thrown .
I've read that article and implemented what it says. My problem is that the function report()
in App\Exception\Handler.php
doesn't trigger if an exception is thrown in one of my Controllers.
My problem : I have an AdminController and a function which inserts some data in Database. The queries are inside a try/catch :
try {
// commands
} catch (\Exception $e){
Log::channel('admin_submissions')->info("Could not save submission. " . $e->getMessage());
return Redirect::back()->withErrors(['Could not save submission. Try again!']);
}
For testing purposes i've inserted inside the try{}
an error to be thrown like :
try {
$error = \Illuminate\Validation\ValidationException::withMessages([
'field_name_1' => ['Validation Message #1'],
'field_name_2' => ['Validation Message #2'],
]);
throw $error;
// commands
But the dd("trigger")
function (look below) is not triggered.
How could i make it so on every exception (everywhere) an email will be sent?
App\Exceptions\Handler.php
I have modified the report function just to check if the exception actually goes through that function :
public function report(Exception $exception)
{
dd("trigger");
if ($this->shouldReport($exception)) {
app('sneaker')->captureException($exception);
}
parent::report($exception);
}
Upvotes: 3
Views: 2516
Reputation: 5613
You must firstly know which kind of exception your application thrown, may be the Exception that is thrown are in the $dontReport
if so, you must firstly remove all exception from that table on you will get report for that Exception
Upvotes: 1