ionic3本机存储错误代码:2

Ger*_*son 1 ionic3

使用ionic3的本机存储时出现错误。它无法正确读取本机存储中的数据。错误代码:2,但没有详细描述。

  public async getToken(): Promise<AccessToken> {
    let token = null;
    let expires = null;
    try{
      token = await this.storage.getItem(this.ACCESSTOKEN_KEY);
      expires = await this.storage.getItem(this.ACCESSTOKEN_EXPIRES_KEY);
    }catch(e){
      alert(JSON.stringify(e));
    }
    if (token == null || expires == null || expires < new Date()) {
      token = null;
    }
    return token;
  }
Run Code Online (Sandbox Code Playgroud)

错误截图

小智 5

错误代码包含一个整数,用于指定发生的错误:

  • NATIVE_WRITE_FAILED = 1
  • ITEM_NOT_FOUND = 2
  • NULL_REFERENCE = 3
  • UNDEFINED_TYPE = 4
  • JSON_ERROR = 5
  • WRONG_PARAMETER = 6