【发布时间】:2021-06-08 13:57:44
【问题描述】:
我正在使用 Angular HTTP.post 方法调用此 API http://10.108.11.239:8080/project/setRule
- 我在浏览器网络选项卡中收到响应,但它在浏览器控制台选项卡中显示内部服务器错误。
服务方式
public postSetup(data: Object, options?: RequestOptionsArgs) {
const headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('USER', this.elem);
let option = options ? options : new RequestOptions({ headers: headers });
return this.http.post(this.API_URL, data, option)
.map((response: Response) => response.json())
.catch((error: any) => {
console.log(error) // able to see error here
return Observable.throw(error);
});
}
Component code
enter code here
try {
this.myservice.postSetup(this.result)
.subscribe(
(data) => {
this.message = data
console.log("response data");
console.log(data);
if (this.message !== null || this.message !== undefined){
this.display = true;
}
else{
this.errorDisplay = true;
let res = JSON.parse( data._body);
console.log("submit scenario error try");// not able to print message here
console.log(res)
}
}
)
}
catch (err) {
this.errorDisplay = true;
let res = JSON.parse(err._body);
console.log("submit scenario error");// not able to print here
console.log(res)
this.sError = res['errorMsg'];
this.errorDesc = res['errorDesc'];
}
注意:订阅功能中没有控件,但是,当使用 HTTP.get 调用其他 API 时,我可以订阅错误。请建议。这里缺少什么?
【问题讨论】:
标签: angular rxjs observable http-post