1
0
Fork 0
mirror of synced 2024-06-26 18:20:43 +12:00

feat: update error codes in the storage API

This commit is contained in:
Christy Jacob 2022-02-06 18:38:59 +04:00
parent 6a8401dfe5
commit d9fbe80317
3 changed files with 8 additions and 2 deletions

View file

@ -239,4 +239,9 @@ return [
'description' => 'The uploaded file is invalid. Please check the file and try again.',
'statusCode' => 403,
],
Exception::STORAGE_FAILED_TO_MOVE_FILE => [
'name' => Exception::STORAGE_FAILED_TO_MOVE_FILE,
'description' => 'Failed to copy the uploaded file.',
'statusCode' => 500,
],
];

View file

@ -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);
throw new Exception('Failed moving file', 500, Exception::STORAGE_FAILED_TO_MOVE_FILE);
}
$mimeType = $device->getFileMimeType($path); // Get mime-type before compression and encryption
@ -127,7 +127,7 @@ App::post('/v1/storage/files')
if (!$antivirus->fileScan($path)) {
$device->delete($path);
throw new Exception('Invalid file', 403);
throw new Exception('Invalid file', 403, Exception::STORAGE_INVALID_FILE);
}
}

View file

@ -67,6 +67,7 @@ class Exception extends \Exception
const STORAGE_INVALID_WRITE_PERMISSIONS = 'storage_invalid_write_permissions';
const STORAGE_INVALID_FILE_SIZE = 'storage_invalid_file_size';
const STORAGE_INVALID_FILE = 'storage_invalid_file';
const STORAGE_FAILED_TO_MOVE_FILE = 'storage_failed_to_move_file';
/** Projects */
const PROJECT_NOT_FOUND = 'project_not_found';