mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Handle exceptions when saving assets in AssetImporter
Added try-catch blocks to manage ValidationException and generic exceptions during asset saving. This ensures proper logging of errors and reporting of unexpected issues, improving robustness and error handling in the asset import process.
This commit is contained in:
parent
617fe85699
commit
6ddaa0bb3e
|
@ -7,6 +7,7 @@ use App\Models\Statuslabel;
|
|||
use App\Models\User;
|
||||
use App\Events\CheckoutableCheckedIn;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Watson\Validating\ValidationException;
|
||||
|
||||
class AssetImporter extends ItemImporter
|
||||
{
|
||||
|
@ -172,8 +173,8 @@ class AssetImporter extends ItemImporter
|
|||
// This sets an attribute on the Loggable trait for the action log
|
||||
$asset->setImported(true);
|
||||
|
||||
if ($asset->save()) {
|
||||
|
||||
try {
|
||||
$asset->save();
|
||||
$this->log('Asset '.$this->item['name'].' with serial number '.$this->item['serial'].' was created');
|
||||
|
||||
// If we have a target to checkout to, lets do so.
|
||||
|
@ -190,8 +191,12 @@ class AssetImporter extends ItemImporter
|
|||
}
|
||||
|
||||
return;
|
||||
}
|
||||
} catch (ValidationException $e) {
|
||||
$this->logError($asset, 'Asset "'.$this->item['name'].'"');
|
||||
} catch (\Exception $e) {
|
||||
report($e);
|
||||
$this->logError($asset, trans('general.something_went_wrong'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue