/* global define */
(function() {
    'use strict';
    define([], function() {
        function makeFunctions($q, $log) {
            /*
             * Take a 304 Error to Calamari API and convert it back to a success response.
             * 304s can be indicative of a state change on the server that has already
             * been completed and can be ignored.
             */
            function intercept304Error(promise) {
                return promise.then(function(resp) {
                    // request succeeded, pass through
                    return resp;
                }, function(resp) {
                    if (resp.status === 304) {
                        // request failed check if it's a 304
                        $log.debug('intercepting 304 and ignoring');
                        var d = $q.defer();
                        /* jshint camelcase: false */
                        d.resolve({
                            status: 200,
                            data: {
                                request_id: null
                            }
                        });
                        // return a new promise, this command was
                        // a NOP
                        return d.promise;
                    }
                    // pass through error
                    return resp;
                });
            }
            return {
                intercept304Error: intercept304Error
            };
        }
        return {
            makeFunctions: makeFunctions
        };
    });
})();

/* global define */
(function() {
    'use strict';
    define([], function() {
        function makeFunctions($q, $log) {
            /*
             * Take a 304 Error to Calamari API and convert it back to a success response.
             * 304s can be indicative of a state change on the server that has already
             * been completed and can be ignored.
             */
            function intercept304Error(promise) {
                return promise.then(function(resp) {
                    // request succeeded, pass through
                    return resp;
                }, function(resp) {
                    var d = $q.defer();
                    if (resp.status === 304) {
                        // request failed check if it's a 304
                        $log.debug('intercepting 304 and ignoring');
                        /* jshint camelcase: false */
                        d.resolve({
                            status: 200,
                            data: {
                                request_id: null
                            }
                        });
                        // return a new promise, this command was
                        // a NOP
                        return d.promise;
                    }
                    // pass through error
                    d.reject(resp)
                    return d.promise;
                });
            }
            return {
                intercept304Error: intercept304Error
            };
        }
        return {
            makeFunctions: makeFunctions
        };
    });
})();

Fix error callback issue in pool modification
Fix error callback issue in pool modification

When the user submit a pool modification with duplicate name
or reduced pg count,rest-api returns the validation error.
But the corresponding error callback is not getting called and
the form doesn't show the errors.

The issue is due to the interception of rest-api response to
change code 304 to code 200 and not properly handling other status
codes. This is now fixed by properly transmitting the errors.

Signed-off-by: Kanagaraj M <a744b691cd98174fb19a473a8cf78b810491e452@redhat.com>
