ngx-braintree
ngx-braintree copied to clipboard
Handling Errors with RxJS 6 and Angular 6
Hi Srikanth,
Thank you for creating such a great module!!
I could not find anything about handling Errors with RxJS 6 with Angular 6.1.
Is the loader supposed to stop when an Error is thrown?
Here is the code that I am using to handle any type of Errors from my backend API.
CC-checkout.service.ts ` import { Observable, throwError } from 'rxjs'; import { catchError } from 'rxjs/operators';
public createCCPurchase(formData){ let clientPurchaseURL = "http://localhost:5000/api/v1/paypal/cc-checkout"
return this.http.post(clientPurchaseURL, formData).pipe(
catchError(this.handleError)
);
}
private handleError(error: HttpErrorResponse) {
if (error.error instanceof ErrorEvent)
{
// A client-side or network error occurred. Handle it accordingly.
console.error('An error occurred:', error.error.message);
}
else {
// The backend returned an unsuccessful response code.
// The response body may contain clues as to what went wrong,
console.error(
`Backend returned code ${error.status}, ` +
`body was: ${error.error}`);
}
// return an observable with a user-facing error message
return throwError(error);
}; `
Can you please let me know what is expected to happen to the NGX-Braintree component when an error is returned and if I am handling the error properly.
If there is anymore information you need please let me know.
Thanks in Advance Sean