Property 'error' does not exist on type '“” | Promise'

前端 未结 3 1417
长发绾君心
长发绾君心 2021-02-13 18:03

I\'m trying to add some error handling to a service, following the Angular guide.

Relevant snippet:

private handleError (error: Response | any) {
  // I         


        
3条回答
  •  隐瞒了意图╮
    2021-02-13 18:37

    I had the same issue, I finally found this solution.

    .catch(error => {
      let errMsg: string;
      const body = JSON.parse(error._body);
      if (body) {
        errMsg = body.error
      } else {
        errMsg = error.message ? error.message : error.toString();
      }
      console.error(errMsg);
      return Promise.reject(errMsg);
    });

提交回复
热议问题