LoginSignup
2
2

More than 5 years have passed since last update.

FileErrorをUser Friendlyに表示する

Posted at

cordovaで開発していたら、FileAPIのFileErrorがエラーコード(数字)でしか取得できないことが分かったので、対応表を作ってみました。

function errorHandler(error){
  var errorDescriptionTable = {
    5: {
      "name": "ENCODING_ERR",
      "description": "The URL is malformed. Make sure that the URL is complete and valid."
    },
    9: {
      "name": "INVALID_MODIFICATION_ERR",
      "description": "The modification requested is not allowed. For example, the app might be trying to move a directory into its own child or moving a file into its parent directory without changing its name."
    },
    7: {
      "name": "INVALID_STATE_ERR",
      "description": "The operation cannot be performed on the current state of the interface object. For example, the state that was cached in an interface object has changed since it was last read from disk."
    },
    6: {
      "name": "NO_MODIFICATION_ALLOWED_ERR",
      "description": "The state of the underlying file system prevents any writing to a file or a directory."
    },
    1: {
      "name": "NOT_FOUND_ERR",
      "description": "A required file or directory could not be found at the time an operation was processed. For example, a file did not exist but was being opened."
    },
    4: {
      "name": "NOT_READABLE_ERR",
      "description": "The file or directory cannot be read, typically due to permission problems that occur after a reference to a file has been acquired (for example, the file or directory is concurrently locked by another application)."
    },
    12: {
      "name": "PATH_EXISTS_ERR",
      "description": "The file or directory with the same path already exists."
    },
    10: {
      "name": "QUOTA_EXCEEDED_ERR",
      "description": "Either there's not enough remaining storage space or the storage quota was reached and the user declined to give more space to the database. To ask for more storage, see Managing HTML5 Offline Storage."
    },
    2: {
      "name": "SECURITY_ERR",
      "description": "Access to the files were denied for one of the following reasons:\nThe files might be unsafe for access within a Web application.\nToo many calls are being made on file resources.\nOther unspecified security error code or situations."
    },
    11: {
      "name": "TYPE_MISMATCH_ERR",
      "description": "The app looked up an entry, but the entry found is of the wrong type. For example, the app is asking for a directory, when the entry is really a file."
    }
  }
  var errorDescription = errorDescriptionTable[error.code];
  console.log('[js] FileError', error.code, errorDescription && errorDescription.name, errorDescription && errorDescription.description);
}
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2