Home:ALL Converter>How to handle RxJs timeout complete - Angular HttpClient

How to handle RxJs timeout complete - Angular HttpClient

Ask Time:2018-11-10T09:49:31         Author:Daniel Delgado

Json Formatter

How to detect an error by timeout operator? I would like to show an alert or something like that just when the server doesn't response.

I have a similiar code in my interceptor:

this.http.post('http://localhost:3000/api/core', data)
            map((response: any) => { // Success...
              return response;
            catchError((error) => { // Error...
              // Timeout over also handled here
              // I want to return an error for timeout
              return throwError(error || 'Timeout Exception');
            finalize(() => {
              console.log('Request it is over');

["rxjs": "^6.0.0", "@angular/http": "^6.0.3",]

Author:Daniel Delgado,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/53235355/how-to-handle-rxjs-timeout-complete-angular-httpclient
Daniel Delgado :

This works\nimport { throwError, TimeoutError } from 'rxjs';\n\ncatchError((error) => { // Error...\n // Handle 'timeout over' error\n if (error instanceof TimeoutError) {\n return throwError('Timeout Exception');\n }\n\n // Return other errors\n return throwError(error);\n})\n\n\nI implemented this at my intecerptor that has other functionalities, the code here",