Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling Errors with RxJS 6 and Angular 6 #91

Open
szarkowicz opened this issue Aug 3, 2018 · 0 comments
Open

Handling Errors with RxJS 6 and Angular 6 #91

szarkowicz opened this issue Aug 3, 2018 · 0 comments

Comments

@szarkowicz
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant