# all files / Core/Services/ HttpResponseInterceptor.js

100% Statements 13/13
100% Branches 2/2
100% Functions 4/4
100% Lines 13/13

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    1

    1

    1

    3

    1
    2

    1
    1
    1
    1
    1
    1

    124

     'use strict';

    // Utilities:
    var Promise = require('bluebird');

    // Module:
    var Core = require('../Core');

    Core.factory('httpResponseInterceptor', function (
        notifierService
    ) {
        return {
            response: handleResponseData,
            responseError: handleResponseError
        };

        function handleResponseData (response) {
            return Promise.resolve(response.config.url.match(/.html$/) ? response : response.data);
        }

        function handleResponseError (response) {
            var error = new Error();
            notifierService.error(response.data.error);
            error.message = response.data.error;
            error.response = response;
            return Promise.reject(error);
        }
    })
    .config(function ($httpProvider) {
        $httpProvider.interceptors.push('httpResponseInterceptor');
    });