2 回答

TA貢獻2036條經驗 獲得超8個贊
我的疏忽。
如果您查看返回的 JSON
....
"message":"Http failure response for https://localhost:44305/api/Entry/GetNext?id=11962: 500 OK",
"error":{
}
}
error似乎是一個空對象
代替事實上error是Blob,我們應該以下面的方式閱讀
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next
.handle(req)
.catch(this.handleError)
}
public handleError = (error: Response) => {
let reader = new FileReader();
let ngNotify = this._ngNotify;
reader.onload = function () {
var result = JSON.parse(this.result);
ngNotify.nofity('Error', result.error);
};
reader.readAsText(error['error']);
return Observable.throw(error)
}
就是這樣。

TA貢獻1842條經驗 獲得超22個贊
我最終通過實現中間件來攔截HttpResponse
、從 blob 中提取錯誤并在 json 中返回消息來解決這個問題。感謝JaapMosselman 的貢獻。
- 2 回答
- 0 關注
- 582 瀏覽
添加回答
舉報