You are here

class UploadException in Plupload integration 8

Same name and namespace in other branches
  1. 2.0.x src/UploadException.php \Drupal\plupload\UploadException

Plupload exception handling route.

Hierarchy

Expanded class hierarchy of UploadException

File

src/UploadException.php, line 10

Namespace

Drupal\plupload
View source
class UploadException extends \Exception {

  /**
   * Error with input stream.
   */
  const INPUT_ERROR = 101;

  /**
   * Error with output stream.
   */
  const OUTPUT_ERROR = 102;

  /**
   * Error moving uploaded file.
   */
  const MOVE_ERROR = 103;

  /**
   * Error with destination folder.
   */
  const DESTINATION_FOLDER_ERROR = 104;

  /**
   * Error with temporary file name.
   */
  const FILENAME_ERROR = 105;

  /**
   * Code to error message mapping.
   *
   * @var array
   */
  public $errorMessages = [
    self::INPUT_ERROR => 'Failed to open input stream.',
    self::OUTPUT_ERROR => 'Failed to open output stream.',
    self::MOVE_ERROR => 'Failed to move uploaded file.',
    self::DESTINATION_FOLDER_ERROR => 'Failed to open temporary directory.',
    self::FILENAME_ERROR => 'Invalid temporary file name.',
  ];

  /**
   * Constructs UploadException.
   *
   * @param int $code
   *   Error code.
   */
  public function __construct($code) {
    $this->code = $code;
    $this->message = $this->errorMessages[$this->code];
  }

  /**
   * Generates and returns JSON response object for the error.
   *
   * @return \Symfony\Component\HttpFoundation\JsonResponse
   *   JSON response object.
   */
  public function getErrorResponse() {
    return new JsonResponse([
      'jsonrpc' => '2.0',
      'error' => [
        'code' => $this->code,
        'message' => $this->errorMessages[$this->code],
      ],
      'id' => 'id',
    ], 500);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
UploadException::$errorMessages public property Code to error message mapping.
UploadException::DESTINATION_FOLDER_ERROR constant Error with destination folder.
UploadException::FILENAME_ERROR constant Error with temporary file name.
UploadException::getErrorResponse public function Generates and returns JSON response object for the error.
UploadException::INPUT_ERROR constant Error with input stream.
UploadException::MOVE_ERROR constant Error moving uploaded file.
UploadException::OUTPUT_ERROR constant Error with output stream.
UploadException::__construct public function Constructs UploadException.