error handling importer
This commit is contained in:
parent
d69f4dd6f6
commit
76f76f73b4
|
|
@ -25,6 +25,7 @@
|
|||
use App\Models\Person\PersonType;
|
||||
use App\Models\Person\PhoneType;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
|
@ -1194,7 +1195,8 @@ public function process(Import $import, ?Authenticatable $user = null): array
|
|||
'user_id' => $user?->getAuthIdentifier(),
|
||||
'event' => 'processing_failed',
|
||||
'level' => 'error',
|
||||
'message' => $e->getMessage(),
|
||||
'message' => $this->safeErrorMessage($e->getMessage()),
|
||||
'context' => $this->exceptionContext($e),
|
||||
]);
|
||||
|
||||
return ['ok' => false, 'status' => 'failed', 'error' => $e->getMessage()];
|
||||
|
|
@ -2482,6 +2484,49 @@ private function safeErrorMessage(string $msg): string
|
|||
return $msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract structured exception details for logging.
|
||||
*/
|
||||
private function exceptionContext(\Throwable $e): array
|
||||
{
|
||||
$ctx = [
|
||||
'exception' => get_class($e),
|
||||
'message' => $this->safeErrorMessage($e->getMessage()),
|
||||
'code' => $e->getCode(),
|
||||
'file' => $e->getFile().':'.$e->getLine(),
|
||||
];
|
||||
|
||||
if (method_exists($e, 'getPrevious') && $e->getPrevious()) {
|
||||
$prev = $e->getPrevious();
|
||||
$ctx['previous'] = [
|
||||
'exception' => get_class($prev),
|
||||
'message' => $this->safeErrorMessage($prev->getMessage()),
|
||||
'code' => $prev->getCode(),
|
||||
'file' => $prev->getFile().':'.$prev->getLine(),
|
||||
];
|
||||
}
|
||||
|
||||
if ($e instanceof QueryException) {
|
||||
$ctx['sql'] = $e->getSql();
|
||||
$ctx['bindings'] = $e->getBindings();
|
||||
$info = $e->errorInfo ?? null;
|
||||
if (is_array($info)) {
|
||||
$ctx['sqlstate'] = $info[0] ?? null;
|
||||
$ctx['driver_error_code'] = $info[1] ?? null;
|
||||
$ctx['driver_error_message'] = $info[2] ?? null;
|
||||
}
|
||||
} elseif (property_exists($e, 'errorInfo')) {
|
||||
$info = $e->errorInfo;
|
||||
if (is_array($info)) {
|
||||
$ctx['sqlstate'] = $info[0] ?? null;
|
||||
$ctx['driver_error_code'] = $info[1] ?? null;
|
||||
$ctx['driver_error_message'] = $info[2] ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
return $ctx;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a trimmed raw data preview (first 8 columns, truncated values) for logging.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user