K
K
Konstantin2020-10-02 21:59:04
Angular
Konstantin, 2020-10-02 21:59:04

Why didn't finilize work on a failed http request?

Method called on click:

public update(): void {
            this.loading = true;
            this.applicationBuildingsService
                .update(this.form.value)
                .pipe(
                    finalize(() => {
                        this.loading = false;
                    }),
                )
                .subscribe(
                    (response) => {
                        this.messageService.showMessage('', 'Операция прошла успешно', 'success');
                        this.dialogRef.close(response);
                    },
                    () => {
                        this.messageService.showMessage('', 'Операция прошла неуспешно', 'error');
                    },
                );
        }


Service:

update(data: Building): Observable<any> {
        let headers = new HttpHeaders();

        if (data.ts) {
            headers = headers.append('TS', data.ts);
        }

        return this.http.post(`${this.baseUrl}/update`, data, { headers });
    }


Why - if the server issues http < 200 then:

finalize(() => {
    this.loading = false;
}),


Does not fire and does not change the status of the variablethis.loading = false;

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question