Skip to content

Commit 062e906

Browse files
committed
Fixes error type definition by severity for display_errors = 1
1 parent 33a0806 commit 062e906

3 files changed

Lines changed: 33 additions & 28 deletions

File tree

src/Handler/Logging.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Error;
66
use ErrorException;
7+
use ErrorHeroModule\HeroConstant;
78
use Exception;
89
use Psr\Http\Message\ServerRequestInterface;
910
use RuntimeException;
@@ -185,11 +186,12 @@ private function collectExceptionData($e)
185186
{
186187
$priority = Logger::ERR;
187188
if ($e instanceof ErrorException && isset(Logger::$errorPriorityMap[$e->getSeverity()])) {
188-
$priority = Logger::$errorPriorityMap[$e->getSeverity()];
189+
$priority = Logger::$errorPriorityMap[$e->getSeverity()];
190+
$errorType = HeroConstant::ERROR_TYPE[$e->getSeverity()];
191+
} else {
192+
$errorType = get_class($e);
189193
}
190194

191-
$exceptionClass = get_class($e);
192-
193195
$errorFile = $e->getFile();
194196
$errorLine = $e->getLine();
195197
$trace = $e->getTraceAsString();
@@ -202,7 +204,7 @@ private function collectExceptionData($e)
202204

203205
return [
204206
'priority' => $priority,
205-
'exceptionClass' => $exceptionClass,
207+
'errorType' => $errorType,
206208
'errorFile' => $errorFile,
207209
'errorLine' => $errorLine,
208210
'trace' => $trace,
@@ -221,7 +223,7 @@ private function collectExceptionExtraData(array $collectedExceptionData)
221223
'url' => $this->serverUrl.$this->requestUri,
222224
'file' => $collectedExceptionData['errorFile'],
223225
'line' => $collectedExceptionData['errorLine'],
224-
'error_type' => $collectedExceptionData['exceptionClass'],
226+
'error_type' => $collectedExceptionData['errorType'],
225227
'trace' => $collectedExceptionData['trace'],
226228
'request_data' => $this->getRequestData(),
227229
];
@@ -291,7 +293,7 @@ public function handleException($e)
291293
$extra = $this->collectExceptionExtraData($collectedExceptionData);
292294
}
293295

294-
$this->sendMail($collectedExceptionData['priority'], $collectedExceptionData['errorMessage'], $extra, '['.$this->serverUrl.'] '.$collectedExceptionData['exceptionClass'].' has thrown');
296+
$this->sendMail($collectedExceptionData['priority'], $collectedExceptionData['errorMessage'], $extra, '['.$this->serverUrl.'] '.$collectedExceptionData['errorType'].' has thrown');
295297
}
296298

297299
/**

src/HeroConstant.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace ErrorHeroModule;
4+
5+
class HeroConstant
6+
{
7+
const ERROR_TYPE = [
8+
E_ERROR => 'E_ERROR',
9+
E_WARNING => 'E_WARNING',
10+
E_PARSE => 'E_PARSE',
11+
E_NOTICE => 'E_NOTICE',
12+
E_CORE_ERROR => 'E_CORE_ERROR',
13+
E_CORE_WARNING => 'E_CORE_WARNING',
14+
E_COMPILE_ERROR => 'E_COMPILE_ERROR',
15+
E_COMPILE_WARNING => 'E_COMPILE_WARNING',
16+
E_USER_ERROR => 'E_USER_ERROR',
17+
E_USER_WARNING => 'E_USER_WARNING',
18+
E_USER_NOTICE => 'E_USER_NOTICE',
19+
E_STRICT => 'E_STRICT',
20+
E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR',
21+
E_DEPRECATED => 'E_DEPRECATED',
22+
E_USER_DEPRECATED => 'E_USER_DEPRECATED',
23+
];
24+
}

src/HeroTrait.php

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,6 @@ trait HeroTrait
2424
*/
2525
private $renderer;
2626

27-
/**
28-
* @var array
29-
*/
30-
private $errorType = [
31-
E_ERROR => 'E_ERROR',
32-
E_WARNING => 'E_WARNING',
33-
E_PARSE => 'E_PARSE',
34-
E_NOTICE => 'E_NOTICE',
35-
E_CORE_ERROR => 'E_CORE_ERROR',
36-
E_CORE_WARNING => 'E_CORE_WARNING',
37-
E_COMPILE_ERROR => 'E_COMPILE_ERROR',
38-
E_COMPILE_WARNING => 'E_COMPILE_WARNING',
39-
E_USER_ERROR => 'E_USER_ERROR',
40-
E_USER_WARNING => 'E_USER_WARNING',
41-
E_USER_NOTICE => 'E_USER_NOTICE',
42-
E_STRICT => 'E_STRICT',
43-
E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR',
44-
E_DEPRECATED => 'E_DEPRECATED',
45-
E_USER_DEPRECATED => 'E_USER_DEPRECATED',
46-
];
47-
4827
/**
4928
* @var ServerRequest|null
5029
*/
@@ -71,7 +50,7 @@ public function execOnShutdown()
7150
*/
7251
public function phpErrorHandler($errorType, $errorMessage, $errorFile, $errorLine)
7352
{
74-
$errorTypeString = $this->errorType[$errorType];
53+
$errorTypeString = HeroConstant::ERROR_TYPE[$errorType];
7554
$errorExcluded = false;
7655
if ($errorLine) {
7756
if (in_array($errorType, $this->errorHeroModuleConfig['display-settings']['exclude-php-errors'])) {

0 commit comments

Comments
 (0)