1

I am controlling in Angular when the Server insert good o my Server can't insert, , but If my server is down I can't receive message:

  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;
                    }

Angular-service:

 addConfig(url, newConfig) {
    return this.http.post(url, newConfig , { responseType: 'text'});
   }

But If I stop my server and execute my app, My modal doesn't close and I can't show modal-error

I get in console,html:

POST http://localhost:8080/create 0 ()
core.js:1449 ERROR HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: "Unknown Error", url: null, ok: false, …}

Then How Can I show my modal-error ?

1 Answer 1

1

The .subscribe() Operator has three paramaters

.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
)

you are currently only using "onNext". So, if the whole stream goes rogue, you do not react to that.

No reaction of your server (a timeout) is a "rogue" stream.

Perhaps try something like

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;
)

warm regards

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.