Angular 控制来自服务器的角度错误

Angular 控制来自服务器的角度错误,angular,Angular,当服务器插入良好时,我控制角度o我的服务器无法插入,但如果我的服务器关闭,我无法接收消息: this.service.addConfig(url, newConfig).subscribe(param => { this.confirmInsert = Boolean(param[0]); this.messageInsert = param[1]; if ( thi

当服务器插入良好时,我控制角度o我的服务器无法插入,但如果我的服务器关闭,我无法接收消息:

  this.service.addConfig(url, newConfig).subscribe(param => {
                    this.confirmInsert = Boolean(param[0]);
                    this.messageInsert = param[1];
                    if ( this.confirmInsert) {
                        this.successInsert = true;
                        this.openModalAdd = false;
                        this.cleanAddForm();
                        this.fetchData();
                    } else {
                        this.errorInsert = true;
                    }
角度服务:

 addConfig(url, newConfig) {
    return this.http.post(url, newConfig , { responseType: 'text'});
   }
但如果我停止服务器并执行应用程序,我的模式不会关闭,也无法显示模式错误

我进入控制台,html:

POST http://localhost:8080/create 0 ()
core.js:1449 ERROR HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: "Unknown Error", url: null, ok: false, …}
那么如何显示模式错误?

subscribe()运算符有三个参数

.subscribe(
   onNext => // Do some magic with the new data
   onError => // Do some dark magic when the world falls apart
   onCompletion => // Enjoy the day, because the stream ended
)
您当前仅使用“onNext”。 所以,如果整个流都变成流氓,你不会对此做出反应

服务器的任何反应(超时)都不是“流氓”流

也许可以试试类似的东西

this.service.addConfig(url, newConfig).subscribe(
param => {
    this.confirmInsert = Boolean(param[0]);
    this.messageInsert = param[1];
    if ( this.confirmInsert) {
        this.successInsert = true;
        this.openModalAdd = false;
        this.cleanAddForm();
        this.fetchData();
    } else {
        this.errorInsert = true;
    },
error => this.errorInsert = true;
)
问候