{"action":"opened","issue":{"url":"https://api.github.com/repos/dreamochi/DayDayUp/issues/55","repository_url":"https://api.github.com/repos/dreamochi/DayDayUp","labels_url":"https://api.github.com/repos/dreamochi/DayDayUp/issues/55/labels{/name}","comments_url":"https://api.github.com/repos/dreamochi/DayDayUp/issues/55/comments","events_url":"https://api.github.com/repos/dreamochi/DayDayUp/issues/55/events","html_url":"https://github.com/dreamochi/DayDayUp/issues/55","id":198229883,"number":55,"title":"$http拦截器 headers注入token","user":{"login":"Somnusochi","id":14160184,"avatar_url":"https://avatars.githubusercontent.com/u/14160184?v=3","gravatar_id":"","url":"https://api.github.com/users/Somnusochi","html_url":"https://github.com/Somnusochi","followers_url":"https://api.github.com/users/Somnusochi/followers","following_url":"https://api.github.com/users/Somnusochi/following{/other_user}","gists_url":"https://api.github.com/users/Somnusochi/gists{/gist_id}","starred_url":"https://api.github.com/users/Somnusochi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Somnusochi/subscriptions","organizations_url":"https://api.github.com/users/Somnusochi/orgs","repos_url":"https://api.github.com/users/Somnusochi/repos","events_url":"https://api.github.com/users/Somnusochi/events{/privacy}","received_events_url":"https://api.github.com/users/Somnusochi/received_events","type":"User","site_admin":false},"labels":[{"id":304426863,"url":"https://api.github.com/repos/dreamochi/DayDayUp/labels/Angular","name":"Angular","color":"eb6420","default":false},{"id":304426750,"url":"https://api.github.com/repos/dreamochi/DayDayUp/labels/JS","name":"JS","color":"fbca04","default":false},{"id":349894447,"url":"https://api.github.com/repos/dreamochi/DayDayUp/labels/%E8%A7%A3%E5%86%B3%E6%96%B9%E6%B3%95","name":"解决方法","color":"0e8a16","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-12-31T12:03:43Z","updated_at":"2016-12-31T12:03:43Z","closed_at":null,"body":"```\r\nangular.module('myApp', [ ]).config(['$httpProvider', function($httpProvider) {\r\n    $httpProvider.interceptors.push(['$q', '$injector', function($q,\r\n      $injector) {\r\n      return {\r\n        // 请求发出之前，可以用于添加各种身份验证信息\r\n        request: function(config) {\r\n          if (localStorage.token) {\r\n            config.headers['token'] = localStorage.token;\r\n          }\r\n          return config;\r\n        },\r\n        // 请求发出时出错\r\n        requestError: function(err) {\r\n          return $q.reject(err);\r\n        },\r\n        // 成功返回了响应\r\n        response: function(res) {\r\n          return res;\r\n        },\r\n        // 返回的响应出错，包括后端返回响应时，设置了非 200 的 http 状态码\r\n        responseError: function(err) {\r\n          return $q.reject(err);\r\n        }\r\n      };\r\n    }]);\r\n  }]);\r\n```"}}
{"actor":{"display_login":"Somnusochi"}}