공통 에러 interceptor
앵귤러에서 $httpProvider를 이용하여 4개의 시점에 interceptor를 설정할 수 있다.
아래 코드처럼 config 안에서 선언해두면 $http로 요청을 보낸 뒤 Error가 발생되면 해당 에러 메시지를 보여줄 수 있다.
https://docs.angularjs.org/api/ng/service/$http
request: interceptors get called with a http config object. The function is free to modify theconfigobject or create a new one. The function needs to return theconfigobject directly, or a promise containing theconfigor a newconfigobject.requestError: interceptor gets called when a previous interceptor threw an error or resolved with a rejection.response: interceptors get called with httpresponseobject. The function is free to modify theresponseobject or create a new one. The function needs to return theresponseobject directly, or as a promise containing theresponseor a newresponseobject.responseError: interceptor gets called when a previous interceptor threw an error or resolved with a rejection.
$httpProvider.interceptors.push(function($q) { return { 'responseError' : function(response) { alert('Error : ' + response.data.error); } } }) This article is licensed under CC BY 4.0 by the author.