我正在尝试在我的应用程序中处理401错误,但错误响应正在给我这个
我的代码段
// service
postPickupData(form: any) {
console.log(JSON.parse(localStorage.getItem("user")));
const userInfo = JSON.parse(localStorage.getItem("user"));
this.token = userInfo.token;
console.log(this.token);
const headers = new Headers({
"Content-Type": "application/x-www-form-urlencoded"
});
// headers.append("auth-token", this.token);
// headers.append("user-id", userInfo.uidx);
const options = new RequestOptions({ headers: headers });
console.log(form);
this.loggedIn = true;
return (
this.http
.post(this.API, form, options)
.map(response => response.json())
.catch(this.handleError)
);
}
private handleError(error: Response) {
console.log(error);
if (error.status === 401 || error.status === 403) {
return Observable.throw("Unauthorised");
}
}
我有一个post请求和一个handleError方法,它应该是未经授权的。我也从observable和map中导入throw并从rxjs中捕获