Commit 9cc0e7a7 authored by Randall Leeds's avatar Randall Leeds

use angular 1.2+ intereptor pattern

parent 2440b74f
...@@ -39,12 +39,8 @@ class FlashProvider ...@@ -39,12 +39,8 @@ class FlashProvider
] ]
angular.module('h.flash', ['ngResource']) flashInterceptor = ['$q', 'flash', ($q, flash) ->
.provider('flash', FlashProvider) response: (response) ->
.config(['$httpProvider', ($httpProvider) ->
$httpProvider.responseInterceptors.push ['$q', 'flash', ($q, flash) ->
(promise) ->
promise.then (response) ->
data = response.data data = response.data
format = response.headers 'content-type' format = response.headers 'content-type'
if format?.match /^application\/json/ if format?.match /^application\/json/
...@@ -59,5 +55,12 @@ angular.module('h.flash', ['ngResource']) ...@@ -59,5 +55,12 @@ angular.module('h.flash', ['ngResource'])
response response
else else
response response
] ]
angular.module('h.flash', ['ngResource'])
.provider('flash', FlashProvider)
.factory('flashInterceptor', flashInterceptor)
.config(['$httpProvider', ($httpProvider) ->
$httpProvider.interceptors.push 'flashInterceptor'
]) ])
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment