Code coverage report for app/components/_common/services/ajax-error-handler.service.js

Statements: 100% (36 / 36)      Branches: 100% (16 / 16)      Functions: 100% (7 / 7)      Lines: 100% (12 / 12)      Ignored: 2 statements, 4 branches     

All files » app/components/_common/services/ » ajax-error-handler.service.js
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                                     
class AjaxErrorHandlerService {
    constructor (Error, $q) {
        Object.assign(this, {Error, $q});
    }
    // directly reject with the human readable error message
    catcher (reason) {
        // reason is:
        // 1. either an error $http response
        // 2. or an error message returned by _success
        const type = typeof reason;
        let code = '$UNEXPECTED';
        if (reason) {
            if (type === 'object') {
                code = reason.message;
            } else if (type === 'string') {
                code = reason;
            }
        }
        return this.$q.reject({
            code,
            text: this.Error.getErrorMessage(code)
        });
    }
}
 
AjaxErrorHandlerService.$inject = ['Error', '$q'];
 
export default AjaxErrorHandlerService;