getDownloadURL 的 Firebase 存储句柄错误

Firebase Storage handle error for getDownloadURL

我在记录来自 Firebase 存储的错误消息和代码时遇到了一些小问题。

这是我的代码:

fileRef
  .getDownloadURL()
  .then((url) => {
    // some code
  })
  .catch((error) => {
    console.log(error)
  })

进入开发者控制台我得到这个:

FirebaseError: Firebase Storage: Object 'bucketname/filename' does not exist. (storage/object-not-found)
{
  "error": {
    "code": 404,
    "message": "Not Found."
  }
}

console.log(error.code) 不起作用(

我怎样才能得到 error.code 和 error.message?

谢谢

事实上,error.code 将 return 此 documentation page 中列出的错误代码之一。

因此,您应该按照 example in the documentation 中所示的方式进行操作(查看“Web 版本 8”选项卡):

fileRef
  .getDownloadURL()
  .then((url) => {
    // some code
  })
.catch((error) => {
  // A full list of error codes is available at
  // https://firebase.google.com/docs/storage/web/handle-errors
  switch (error.code) {
    case 'storage/object-not-found':
      // File doesn't exist
      break;
    case 'storage/unauthorized':
      // User doesn't have permission to access the object
      break;
    case 'storage/canceled':
      // User canceled the upload
      break;

    // ...

    case 'storage/unknown':
      // Unknown error occurred, inspect the server response
      break;
  }
});