From cb52a4cdc2daa45a61c728f5ec83603e6c6a71fa Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Tue, 3 Feb 2015 00:23:12 +0100 Subject: Rework error handling in upload validator Signed-off-by: Florian Pritz --- application/service/files.php | 8 +++++--- application/service/user.php | 1 - 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'application/service') diff --git a/application/service/files.php b/application/service/files.php index 8d8b1d01a..c270500ef 100644 --- a/application/service/files.php +++ b/application/service/files.php @@ -89,6 +89,10 @@ class files { $CI =& get_instance(); $errors = array(); + if (empty($files)) { + throw new \exceptions\UserInputException("file/no-file", "No file was uploaded or unknown error occured."); + } + foreach ($files as $key => $file) { $error_message = ""; @@ -113,7 +117,6 @@ class files { } else { $error_message = "Unknown error code: ".$file['error'].". Please report a bug."; } - } $filesize = filesize($file['tmp_name']); @@ -127,9 +130,8 @@ class files { "formfield" => $file["formfield"], "message" => $error_message, ); + throw new \exceptions\FileUploadVerifyException("file/upload-verify", "Failed to verify uploaded file(s)", $errors); } } - - return $errors; } } diff --git a/application/service/user.php b/application/service/user.php index 97f2531f9..16fa62272 100644 --- a/application/service/user.php +++ b/application/service/user.php @@ -23,7 +23,6 @@ class user { { $CI =& get_instance(); - $valid_levels = $CI->muser->get_access_levels(); if (array_search($access_level, $valid_levels) === false) { throw new \exceptions\UserInputException("user/validation/access_level/invalid", "Invalid access levels requested."); -- cgit v1.2.3-24-g4f1b