fix response errors

This commit is contained in:
2023-02-22 20:21:34 +10:00
parent f0accc2e33
commit 0f8f18943b

View File

@@ -59,7 +59,7 @@ class MediaController extends ApiController
{ {
$file = $request->file('file'); $file = $request->file('file');
if ($file === null) { if ($file === null) {
return $this->respondError(['file' => 'An error occurred uploading the file to the server.']); return $this->respondWithErrors(['file' => 'The browser did not upload the file correctly to the server.']);
} }
if ($file->isValid() !== true) { if ($file->isValid() !== true) {
@@ -68,9 +68,9 @@ class MediaController extends ApiController
case UPLOAD_ERR_FORM_SIZE: case UPLOAD_ERR_FORM_SIZE:
return $this->respondTooLarge(); return $this->respondTooLarge();
case UPLOAD_ERR_PARTIAL: case UPLOAD_ERR_PARTIAL:
return $this->respondError(['file' => 'The file upload was interrupted.']); return $this->respondWithErrors(['file' => 'The file upload was interrupted.']);
default: default:
return $this->respondError(['file' => 'An error occurred uploading the file to the server.']); return $this->respondWithErrors(['file' => 'An error occurred uploading the file to the server.']);
} }
} }
@@ -82,7 +82,7 @@ class MediaController extends ApiController
$mime = $file->getMimeType(); $mime = $file->getMimeType();
$fileInfo = Media::store($file, empty($request->input('permission'))); $fileInfo = Media::store($file, empty($request->input('permission')));
if ($fileInfo === null) { if ($fileInfo === null) {
return $this->respondError( return $this->respondWithErrors(
['file' => 'The file could not be stored on the server'], ['file' => 'The file could not be stored on the server'],
HttpResponseCodes::HTTP_INTERNAL_SERVER_ERROR HttpResponseCodes::HTTP_INTERNAL_SERVER_ERROR
); );
@@ -121,7 +121,7 @@ class MediaController extends ApiController
$oldPath = $medium->path(); $oldPath = $medium->path();
$fileInfo = Media::store($file, empty($request->input('permission'))); $fileInfo = Media::store($file, empty($request->input('permission')));
if ($fileInfo === null) { if ($fileInfo === null) {
return $this->respondError( return $this->respondWithErrors(
['file' => 'The file could not be stored on the server'], ['file' => 'The file could not be stored on the server'],
HttpResponseCodes::HTTP_INTERNAL_SERVER_ERROR HttpResponseCodes::HTTP_INTERNAL_SERVER_ERROR
); );