function APIResponseInterceptor() { this.execute = function(xhr, requestInfo) { var httpStatus = xhr.status; var httpStatusText = xhr.statusText; var response = errorObject; if (HTTPServiceCodes['server_error'].hasOwnProperty(httpStatus)){ redirectTo(httpStatus, 'error'); } if (!HTTPServiceCodes.hasOwnProperty(requestInfo.serviceId)) { response.error = true; response.message = 'Unknown service'; return response; } else if (!HTTPServiceCodes[requestInfo.serviceId].hasOwnProperty(requestInfo.operation)) { response.error = true; response.message = 'Unknown operation'; return response; } var serviceCodes = HTTPServiceCodes[requestInfo.serviceId][requestInfo.operation]; var found = false; for (var code in serviceCodes) { if (serviceCodes.hasOwnProperty(code) && code == httpStatus) { found = true; response.error = serviceCodes[code].is_error; response.code = serviceCodes[code].error_code; response.message = serviceCodes[code].text; break; } } if (!found) { response.error = true; response.message = HTTPServiceCodes['unexpected'].replace(/http_code/gi, httpStatus).replace(/http_text/gi, httpStatusText); return response; } return response; }; }