Skip to content

Commit 98d378d

Browse files
committed
Not all exceptions is subclass of exceptions in Laravel it seems like. Also look for the word "Exception" in the class name.
1 parent c6bd4d6 commit 98d378d

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

src/Models/LogToDbCreateObject.php

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,30 @@ public function setContextAttribute(array $value)
8484
if (!empty($value['exception'])) {
8585
$exception = $value['exception'];
8686
if (get_class($exception) === \Exception::class
87-
|| is_subclass_of($exception, \Exception::class)) {
87+
|| is_subclass_of($exception, \Exception::class)
88+
|| strpos(get_class($exception), "Exception") !== false) {
8889
$newexception = [];
89-
$newexception['class'] = get_class($exception);
90-
$newexception['message'] = $exception->getMessage();
91-
$newexception['code'] = $exception->getCode();
92-
$newexception['file'] = $exception->getFile();
93-
$newexception['line'] = $exception->getLine();
94-
$newexception['trace'] = $exception->getTrace();
95-
$newexception['previous'] = $exception->getPrevious();
96-
90+
if (method_exists($exception, 'getMessage')) {
91+
$newexception['message'] = $exception->getMessage();
92+
}
93+
if (method_exists($exception, 'getCode')) {
94+
$newexception['code'] = $exception->getCode();
95+
}
96+
if (method_exists($exception, 'getFile')) {
97+
$newexception['file'] = $exception->getFile();
98+
}
99+
if (method_exists($exception, 'getLine')) {
100+
$newexception['line'] = $exception->getLine();
101+
}
102+
if (method_exists($exception, 'getTrace')) {
103+
$newexception['trace'] = $exception->getTrace();
104+
}
105+
if (method_exists($exception, 'getPrevious')) {
106+
$newexception['previous'] = $exception->getPrevious();
107+
}
108+
if (method_exists($exception, 'getSeverity')) {
109+
$newexception['severity'] = $exception->getSeverity();
110+
}
97111
$value['exception'] = $newexception;
98112
}
99113
}

0 commit comments

Comments
 (0)