mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 23:54:44 +02:00
Improve egg import error handling (#703)
* make sure read & write are successful * show exception message in notification
This commit is contained in:
parent
8eebb82eba
commit
a9b76a0f51
@ -142,6 +142,7 @@ class ListEggs extends ListRecords
|
|||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
Notification::make()
|
Notification::make()
|
||||||
->title('Import Failed')
|
->title('Import Failed')
|
||||||
|
->body($exception->getMessage())
|
||||||
->danger()
|
->danger()
|
||||||
->send();
|
->send();
|
||||||
|
|
||||||
@ -158,6 +159,7 @@ class ListEggs extends ListRecords
|
|||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
Notification::make()
|
Notification::make()
|
||||||
->title('Import Failed')
|
->title('Import Failed')
|
||||||
|
->body($exception->getMessage())
|
||||||
->danger()
|
->danger()
|
||||||
->send();
|
->send();
|
||||||
|
|
||||||
|
@ -86,7 +86,9 @@ class EggImporterService
|
|||||||
$tmpDir = TemporaryDirectory::make()->deleteWhenDestroyed();
|
$tmpDir = TemporaryDirectory::make()->deleteWhenDestroyed();
|
||||||
$tmpPath = $tmpDir->path($info['basename']);
|
$tmpPath = $tmpDir->path($info['basename']);
|
||||||
|
|
||||||
file_put_contents($tmpPath, file_get_contents($url));
|
if (!file_put_contents($tmpPath, file_get_contents($url))) {
|
||||||
|
throw new InvalidFileUploadException('Could not write temporary file.');
|
||||||
|
}
|
||||||
|
|
||||||
return $this->fromFile(new UploadedFile($tmpPath, $info['basename'], 'application/json'), $egg);
|
return $this->fromFile(new UploadedFile($tmpPath, $info['basename'], 'application/json'), $egg);
|
||||||
}
|
}
|
||||||
@ -94,7 +96,6 @@ class EggImporterService
|
|||||||
/**
|
/**
|
||||||
* Takes an uploaded file and parses out the egg configuration from within.
|
* Takes an uploaded file and parses out the egg configuration from within.
|
||||||
*
|
*
|
||||||
* @throws \JsonException
|
|
||||||
* @throws \App\Exceptions\Service\InvalidFileUploadException
|
* @throws \App\Exceptions\Service\InvalidFileUploadException
|
||||||
*/
|
*/
|
||||||
protected function parseFile(UploadedFile $file): array
|
protected function parseFile(UploadedFile $file): array
|
||||||
@ -103,7 +104,11 @@ class EggImporterService
|
|||||||
throw new InvalidFileUploadException('The selected file was not uploaded successfully');
|
throw new InvalidFileUploadException('The selected file was not uploaded successfully');
|
||||||
}
|
}
|
||||||
|
|
||||||
$parsed = json_decode($file->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
try {
|
||||||
|
$parsed = json_decode($file->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||||
|
} catch (\JsonException $exception) {
|
||||||
|
throw new InvalidFileUploadException('Could not read JSON file: ' . $exception->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
$version = $parsed['meta']['version'] ?? '';
|
$version = $parsed['meta']['version'] ?? '';
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user