1

I need your help to recommend me documents or links that solve my question. Actually in Angular 4, I want to customize error from api services. For example, if the server responses the request with error, the error will be shown to user. My question is how can I get all errors from server and for each ones write codes for user in front-end. Thank you in advance.

4
  • link this could be helpful, I recommend that you should try to add specific error code in your backend (e.g spring @ExceptionHandler ) and in your front end You can try to use .catch((err: any) => { if(err.status == 'your code e.g 84573'){ console.error('An special error occurred coneccted to the business logic:', err.error); } }); This(more or less this) was working in angularjs - probably will work here too but i'm not 100% sure. Commented Feb 27, 2018 at 6:49
  • 1
    Possible duplicate of Catching errors in Angular HttpClient Commented Feb 27, 2018 at 7:20
  • @MacRyze thank you, it is so easy :) Commented Feb 27, 2018 at 7:24
  • @zgue thanks a lot, it is useful. Commented Feb 27, 2018 at 7:25

1 Answer 1

1

You can make HTTP interceptor and collect all server error in single service and modify them according to your requirement.

This is one of the simplest implementation I have found https://hackernoon.com/global-http-request-error-catching-in-angular-486a319f59ab

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.