From 434f2cd433c68a1de4d5dc9e658a5f7fc781ebef Mon Sep 17 00:00:00 2001 From: Luke Towers Date: Fri, 5 Jun 2020 15:52:27 -0600 Subject: [PATCH] Improve error handling for UploadableWidgets --- modules/backend/traits/UploadableWidget.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/backend/traits/UploadableWidget.php b/modules/backend/traits/UploadableWidget.php index 03f6bfa47..d1895d8f4 100644 --- a/modules/backend/traits/UploadableWidget.php +++ b/modules/backend/traits/UploadableWidget.php @@ -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;