Skip to content

Commit 91c5ddb

Browse files
authored
Catch icon exception when importing egg (#2299)
1 parent 562be98 commit 91c5ddb

3 files changed

Lines changed: 11 additions & 6 deletions

File tree

app/Models/Traits/HasIcon.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function writeIcon(string $extension, string $data): string
4949
};
5050

5151
if (is_null($normalizedExtension)) {
52-
throw new Exception(trans('admin/egg.import.unknown_extension'));
52+
throw new Exception(trans('admin/egg.import.unknown_extension', ['extension' => $extension]));
5353
}
5454

5555
$fileName = static::getIconStoragePath() . "/$this->uuid.$normalizedExtension";

app/Services/Eggs/Sharing/EggImporterService.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use App\Exceptions\Service\InvalidFileUploadException;
77
use App\Models\Egg;
88
use App\Models\EggVariable;
9+
use Exception;
910
use Illuminate\Database\ConnectionInterface;
1011
use Illuminate\Http\UploadedFile;
1112
use Illuminate\Support\Arr;
@@ -268,11 +269,15 @@ private function saveEggIconFromBase64(string $base64String, Egg $egg): void
268269
return;
269270
}
270271

271-
$extension = strtolower($matches[1]);
272-
$data = base64_decode($matches[2]);
272+
try {
273+
$extension = strtolower($matches[1]);
274+
$data = base64_decode($matches[2]);
273275

274-
if ($data) {
275-
$egg->writeIcon($extension, $data);
276+
if ($data) {
277+
$egg->writeIcon($extension, $data);
278+
}
279+
} catch (Exception $exception) {
280+
report($exception);
276281
}
277282
}
278283

lang/en/admin/egg.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
'no_local_ip' => 'Local IP Addresses are not allowed',
3131
'unsupported_format' => 'Unsupported Format. Supported Formats: :formats',
3232
'invalid_url' => 'The provided URL is invalid',
33-
'unknown_extension' => 'Unknown icon extension',
33+
'unknown_extension' => 'Unknown icon extension (:extension)',
3434
'could_not_write' => 'Could not write icon to disk',
3535
'icon_deleted' => 'Icon Deleted',
3636
'no_icon' => 'No Icon Provided',

0 commit comments

Comments
 (0)