Improve error handling for UploadableWidgets

This commit is contained in:
Luke Towers 2020-06-05 15:52:27 -06:00
parent 547d9bffeb
commit 434f2cd433
1 changed files with 7 additions and 2 deletions

View File

@ -69,7 +69,12 @@ trait UploadableWidget
* See mime type handling in the asset manager
*/
if (!$uploadedFile->isValid()) {
throw new ApplicationException($uploadedFile->getErrorMessage());
if ($uploadedFile->getError() === UPLOAD_ERR_OK) {
$message = "The file \"{$uploadedFile->getClientOriginalName()}\" uploaded successfully but wasn't available at {$uploadedFile->getPathName()}. Check to make sure that nothing moved it away.";
} else {
$message = $uploadedFile->getErrorMessage();
}
throw new ApplicationException($message);
}
// Use the configured upload path unless it's null, in which case use the user-provided path
@ -113,7 +118,7 @@ trait UploadableWidget
'result' => 'success'
]);
} catch (\Exception $ex) {
$response = Response::make($ex->getMessage(), 400);
throw new ApplicationException($ex->getMessage());
}
return $response;