feat: use general server errors in storage API
This commit is contained in:
parent
3b420fdeed
commit
3cdccf0024
|
@ -293,11 +293,6 @@ return [
|
|||
'description' => 'The requested storage device could not be found.',
|
||||
'code' => 400,
|
||||
],
|
||||
Exception::STORAGE_FILE_DELETION_FAILED => [
|
||||
'name' => Exception::STORAGE_FILE_DELETION_FAILED,
|
||||
'description' => 'There was an issue deleting the file from the database.',
|
||||
'code' => 500,
|
||||
],
|
||||
Exception::STORAGE_FILE_EMPTY => [
|
||||
'name' => Exception::STORAGE_FILE_EMPTY,
|
||||
'description' => 'Empty file passed to the endpoint.',
|
||||
|
@ -318,11 +313,6 @@ return [
|
|||
'description' => 'The uploaded file is invalid. Please check the file and try again.',
|
||||
'code' => 403,
|
||||
],
|
||||
Exception::STORAGE_FAILED_TO_WRITE_FILE => [
|
||||
'name' => Exception::STORAGE_FAILED_TO_WRITE_FILE,
|
||||
'description' => 'Failed to save the uploaded file.',
|
||||
'code' => 500,
|
||||
],
|
||||
|
||||
/** Functions */
|
||||
Exception::FUNCTION_NOT_FOUND => [
|
||||
|
|
|
@ -116,7 +116,7 @@ App::post('/v1/storage/files')
|
|||
$path = $device->getPath(\uniqid().'.'.\pathinfo($file['name'], PATHINFO_EXTENSION));
|
||||
|
||||
if (!$device->upload($file['tmp_name'], $path)) { // TODO deprecate 'upload' and replace with 'move'
|
||||
throw new Exception('Failed moving file', 500, Exception::STORAGE_FAILED_TO_MOVE_FILE);
|
||||
throw new Exception('Failed moving file', 500, Exception::GENERAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
$mimeType = $device->getFileMimeType($path); // Get mime-type before compression and encryption
|
||||
|
@ -141,7 +141,7 @@ App::post('/v1/storage/files')
|
|||
$data = OpenSSL::encrypt($data, OpenSSL::CIPHER_AES_128_GCM, $key, 0, $iv, $tag);
|
||||
|
||||
if (!$device->write($path, $data, $mimeType)) {
|
||||
throw new Exception('Failed to save file', 500, Exception::STORAGE_FAILED_TO_WRITE_FILE);
|
||||
throw new Exception('Failed to save file', 500, Exception::GENERAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
$sizeActual = $device->getFileSize($path);
|
||||
|
@ -304,7 +304,7 @@ App::get('/v1/storage/files/:fileId/preview')
|
|||
$storage = 'files';
|
||||
|
||||
if (!\extension_loaded('imagick')) {
|
||||
throw new Exception('Imagick extension is missing', 500, Exception::IMAGIC_EXTENSION_MISSING);
|
||||
throw new Exception('Imagick extension is missing', 500, Exception::GENERAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
if (!Storage::exists($storage)) {
|
||||
|
@ -671,7 +671,7 @@ App::delete('/v1/storage/files/:fileId')
|
|||
|
||||
if ($device->delete($file->getAttribute('path', ''))) {
|
||||
if (!$dbForProject->deleteDocument('files', $fileId)) {
|
||||
throw new Exception('Failed to remove file from DB', 500, Exception::STORAGE_FILE_DELETION_FAILED);
|
||||
throw new Exception('Failed to remove file from DB', 500, Exception::GENERAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -73,12 +73,10 @@ class Exception extends \Exception
|
|||
const STORAGE_ERROR = 'storage_error';
|
||||
const STORAGE_FILE_NOT_FOUND = 'storage_file_not_found';
|
||||
const STORAGE_DEVICE_NOT_FOUND = 'storage_device_not_found';
|
||||
const STORAGE_FILE_DELETION_FAILED = 'storage_file_deletion_failed';
|
||||
const STORAGE_FILE_EMPTY = 'storage_file_empty';
|
||||
const STORAGE_FILE_TYPE_UNSUPPORTED = 'storage_file_type_unsupported';
|
||||
const STORAGE_INVALID_FILE_SIZE = 'storage_invalid_file_size';
|
||||
const STORAGE_INVALID_FILE = 'storage_invalid_file';
|
||||
const STORAGE_FAILED_TO_WRITE_FILE = 'storage_failed_to_write_file';
|
||||
|
||||
/** Functions */
|
||||
const FUNCTION_NOT_FOUND = 'function_not_found';
|
||||
|
|
Loading…
Reference in a new issue