Discuss the role and implementation of interceptors in AngularJS.

Instruction: Explain what interceptors are in AngularJS and how to implement them for request and response manipulation.

Context: This question evaluates the candidate's knowledge of advanced HTTP communication handling within AngularJS applications.

Updated

Official answer available

Read the opening below, then unlock the full answer and practical guidance.

AngularJS $http interceptors transform the request/response promise chain for $http calls using that injector. They do not automatically intercept native fetch, every third-party request or server-side traffic.

An interceptor can implement request, requestError, response and responseError. Return the appropriate config/response or promise; returning an ordinary value from an error handler can convert a rejection into success. Preserve rejection unless recovery is intentional...

Related Questions