better error handling

This commit is contained in:
2023-10-19 19:20:17 +10:00
parent 8c910ed5f3
commit 114db744b4
3 changed files with 9 additions and 8 deletions

View File

@@ -184,6 +184,7 @@ class MediaController extends ApiController
array_key_exists('mime_type', $data) === true && array_key_exists('mime_type', $data) === true &&
$data['mime_type'] !== "") { $data['mime_type'] !== "") {
$error = Media::verifyStorage($data['mime_type'], $data['security']['type'], $data['storage']); $error = Media::verifyStorage($data['mime_type'], $data['security']['type'], $data['storage']);
// Log::error($data['mime_type'] . ' - ' . $data['security']['type'] . ' - ' . $data['storage']);
switch($error) { switch($error) {
case Media::STORAGE_VALID: case Media::STORAGE_VALID:
break; break;
@@ -192,7 +193,7 @@ class MediaController extends ApiController
case Media::STORAGE_NOT_FOUND: case Media::STORAGE_NOT_FOUND:
return $this->respondWithErrors(['storage' => 'Storage was not found.']); return $this->respondWithErrors(['storage' => 'Storage was not found.']);
case Media::STORAGE_INVALID_SECURITY: case Media::STORAGE_INVALID_SECURITY:
return $this->respondWithErrors(['storage' => 'Storage invalid for security value.']); return $this->respondWithErrors(['storage' => 'Storage invalid for this security requirement.']);
default: default:
return $this->respondWithErrors(['storage' => 'Storage verification error occurred.']); return $this->respondWithErrors(['storage' => 'Storage verification error occurred.']);
} }

View File

@@ -1020,11 +1020,8 @@ class Media extends Model
$storage = 'private'; $storage = 'private';
} }
} else { } else {
try { $disks = config('filesystems.disks');
if(Storage::disk($storage)->exists('') === false) { if(array_key_exists($storage, $disks) === false) {
return Media::STORAGE_NOT_FOUND;
}
} catch(\Exception $e) {
return Media::STORAGE_NOT_FOUND; return Media::STORAGE_NOT_FOUND;
} }

View File

@@ -1088,14 +1088,17 @@ const uploadFileById = (uploadId: string, file: File): void => {
content: `Cannot upload the file ${file.name} as it larger than ${max_upload_size.value}.`, content: `Cannot upload the file ${file.name} as it larger than ${max_upload_size.value}.`,
}); });
} else { } else {
const message = error.data.message
? " " + error.data.message
: "";
useToastStore().addToast({ useToastStore().addToast({
title: "File upload error", title: "File upload error",
type: "danger", type: "danger",
content: `Cannot upload the file ${file.name} as a server error occurred.`, content: `Cannot upload the file ${file.name} as a server error occurred.${message}`,
}); });
} }
console.log(error);
removeMediaItem(uploadId); removeMediaItem(uploadId);
}); });
}; };