0

I have this code to save information in Firebase, it works perfectly but I need to check if it gives me any kind of error, for example that there is no internet connection.

How do I do it?

Thank's

saveData( data: Data ) {
   return this.http.post(`${ this.url }/dataX.json`, data)
       .pipe(
           map( res => {
             return res;
            })
         )
      ;
 }

1 Answer 1

1

There are two options to check errors:

  1. Receive the error in subscription section.
yourService.saveData(xxx).subscribe(
    (res) => {
        // Successful Response
    },
    (err) => {
        // Error handling
    }
  1. Catch the error using catchError rxjs operator
return this.http.post(`${ this.url }/dataX.json`, data)
   .pipe(
        catchError(err => {
            // Error handling
        })
   );
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.