Skip to content

Commit 376ebb1

Browse files
authored
Preserve laravel error handler (#1760)
* Preserve laravel error handler * Return if there isnt previus handler
1 parent 7d3b28f commit 376ebb1

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/LaravelDebugbar.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ class LaravelDebugbar extends DebugBar
101101
*/
102102
protected $is_lumen = false;
103103

104+
/**
105+
* Laravel default error handler
106+
*
107+
* @var callable|null
108+
*/
109+
protected $prevErrorHandler = null;
110+
104111
protected ?string $editorTemplateLink = null;
105112
protected array $remoteServerReplacements = [];
106113
protected bool $responseIsModified = false;
@@ -173,7 +180,7 @@ public function boot()
173180

174181
// Set custom error handler
175182
if ($config->get('debugbar.error_handler', false)) {
176-
set_error_handler([$this, 'handleError']);
183+
$this->prevErrorHandler = set_error_handler([$this, 'handleError']);
177184
}
178185

179186
$this->selectStorage($this);
@@ -649,16 +656,17 @@ public function addCollector(DataCollectorInterface $collector)
649656
*/
650657
public function handleError($level, $message, $file = '', $line = 0, $context = [])
651658
{
652-
$exception = new \ErrorException($message, 0, $level, $file, $line);
653-
if (error_reporting() & $level) {
654-
throw $exception;
655-
}
656-
657-
$this->addThrowable($exception);
659+
$this->addThrowable(new \ErrorException($message, 0, $level, $file, $line));
658660
if ($this->hasCollector('messages')) {
659661
$file = $file ? ' on ' . $this['messages']->normalizeFilePath($file) . ":{$line}" : '';
660662
$this['messages']->addMessage($message . $file, 'deprecation');
661663
}
664+
665+
if (! $this->prevErrorHandler) {
666+
return;
667+
}
668+
669+
return call_user_func($this->prevErrorHandler, $level, $message, $file, $line, $context);
662670
}
663671

664672
/**

0 commit comments

Comments
 (0)