File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
src/Illuminate/Foundation/Exceptions Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -278,6 +278,10 @@ protected function shouldntReport(Throwable $e)
278278 */
279279 protected function exceptionContext (Throwable $ e )
280280 {
281+ if (method_exists ($ e , 'context ' )) {
282+ return $ e ->context ();
283+ }
284+
281285 return [];
282286 }
283287
Original file line number Diff line number Diff line change @@ -76,6 +76,15 @@ public function testHandlerReportsExceptionAsContext()
7676 $ this ->handler ->report (new RuntimeException ('Exception message ' ));
7777 }
7878
79+ public function testHandlerCallsContextMethodIfPresent ()
80+ {
81+ $ logger = m::mock (LoggerInterface::class);
82+ $ this ->container ->instance (LoggerInterface::class, $ logger );
83+ $ logger ->shouldReceive ('error ' )->withArgs (['Exception message ' , m::subset (['foo ' => 'bar ' ])])->once ();
84+
85+ $ this ->handler ->report (new ContextProvidingException ('Exception message ' ));
86+ }
87+
7988 public function testHandlerReportsExceptionWhenUnReportable ()
8089 {
8190 $ logger = m::mock (LoggerInterface::class);
@@ -283,6 +292,16 @@ public function report()
283292 }
284293}
285294
295+ class ContextProvidingException extends Exception
296+ {
297+ public function context ()
298+ {
299+ return [
300+ 'foo ' => 'bar ' ,
301+ ];
302+ }
303+ }
304+
286305interface ReportingService
287306{
288307 public function send ($ message );
You can’t perform that action at this time.
0 commit comments