3 namespace Drupal\dropzonejs;
5 use Symfony\Component\HttpFoundation\JsonResponse;
8 * Class UploadException.
10 class UploadException extends \Exception {
13 * Error with input stream.
15 const INPUT_ERROR = 101;
18 * Error with output stream.
20 const OUTPUT_ERROR = 102;
23 * Error moving uploaded file.
25 const MOVE_ERROR = 103;
28 * Error with destination folder.
30 const DESTINATION_FOLDER_ERROR = 104;
33 * Error with temporary file name.
35 const FILENAME_ERROR = 105;
38 * File upload resulted in error.
40 const FILE_UPLOAD_ERROR = 106;
43 * Code to error message mapping.
47 public $errorMessages = array(
48 self::INPUT_ERROR => 'Failed to open input stream.',
49 self::OUTPUT_ERROR => 'Failed to open output stream.',
50 self::MOVE_ERROR => 'Failed to move uploaded file.',
51 self::DESTINATION_FOLDER_ERROR => 'Failed to open temporary directory for write.',
52 self::FILENAME_ERROR => 'Invalid temporary file name.',
53 self::FILE_UPLOAD_ERROR => 'The file upload resulted in an error on php level. See http://php.net/manual/en/features.file-upload.errors.php',
57 * Constructs UploadException.
61 * @param string|null $message
62 * The error message. Defaults to null.
64 public function __construct($code, $message = NULL) {
66 $this->message = isset($message) ? $message : $this->errorMessages[$this->code];
70 * Generates and returns JSON response object for the error.
72 * @return \Symfony\Component\HttpFoundation\JsonResponse
73 * JSON response object.
75 public function getErrorResponse() {
76 return new JsonResponse(
79 'error' => $this->errorMessages[$this->code],