如何使用.toPromise()读取错误的请求(400)响应.catch()
这是我的代码:
testConnection() {
this.http.get(
this.backendBaseUrl + `api/Test`, {observe: 'response'}
).toPromise()
.then(response => {
alert(`successfully.`);
})
.catch((error: HttpErrorResponse ) => {
alert(`connection not successful:\n${error}`); // error.error, error.message => undefined
});
}
它仅作为错误请求提醒
Headers:
Preview/ Response
Alert
更新:我想提醒预览/响应的响应,而不仅仅是错误的请求
Solved: Found the issue, was having a HttpInterceptor which was removing the error message