What is an interceptor? What are common uses of it?

Technology CommunityCategory: AngularJSWhat is an interceptor? What are common uses of it?
VietMX Staff asked 3 years ago

An interceptor is a middleware code where all the $http requests go through.

The interceptor is a factory that are registered in $httpProvider. There are two types of requests that go through the interceptor, request and response (with requestError and responseError respectively).

This piece of code is very useful for error handling, authentication or middleware in all the requests/responses.