function AmazonAPIResponseValidator(e,t){function f(){l(),s&&c()}function l(){n=AmazonWorker.ResponseMessageCode.SUCCESS,r="",i=0,s=t,o=null,u="",a={valid:!1}}function c(t){var a,f=t||s,l,c;for(c=0;c<f.responses.length;c++){_errorResponse=f.responses[c].status?f.responses[0].status.toString():"",l=f.responses[c].responseJSON;var h=f.responses[c].status;if(l){o=v(l);if(o){i=e.errorDefines.getErrorCode("AMAZON_CUSTOM_ERROR"),u="AMAZON_CUSTOM_ERROR",n=h,r=f.responses[c].statusText;break}if(l.error==="invalid_grant"){n=l.error,r=l.error_description,i=e.errorDefines.getErrorCode("AMAZON_INVALID_REFRESH_TOKEN_ERROR"),u="AMAZON_INVALID_REFRESH_TOKEN_ERROR";break}if(h==AmazonWorker.ResponseMessageCode.SUCCESS)continue}n=h,r=l?JSON.stringify(l):f.responses[c].statusText;switch(h){case AmazonWorker.ResponseMessageCode.UNAUTHORIZED:case AmazonWorker.ResponseMessageCode.FORBIDDEN:i=e.errorDefines.getErrorCode("AMAZON_UNAUTHORIZED_ACCESS"),u="AMAZON_UNAUTHORIZED_ACCESS";break;case AmazonWorker.ResponseMessageCode.BAD_REQUEST:case AmazonWorker.ResponseMessageCode.METHOD_NOT_ALLOWED:i=e.errorDefines.getErrorCode("AMAZON_INVALID_REQUEST"),u="AMAZON_INVALID_REQUEST";break;case AmazonWorker.ResponseMessageCode.NOT_FOUND:i=e.errorDefines.getErrorCode("AMAZON_INVALID_NODE"),u="AMAZON_INVALID_NODE";break;default:i=e.errorDefines.getErrorCode("MUSIC_SERVICE_COULD_NOT_CONNECT"),u="MUSIC_SERVICE_COULD_NOT_CONNECT"}}}function h(){var e=!1;if(n===AmazonWorker.ResponseMessageCode.UNAUTHORIZED||n===AmazonWorker.ResponseMessageCode.FORBIDDEN)e=!0;return e}function p(){var e={valid:!0};if(n!==AmazonWorker.ResponseMessageCode.SUCCESS||i!==0)e={valid:!1,errorCode:i,errorCodeFromAPI:n,errorMessageFromAPI:r,customError:o,errorName:u};return e}function d(){return n===AmazonWorker.ResponseMessageCode.SUCCESS&&i===0}function v(e){if(e&&e.result!=undefined&&e.result!=""){var t=e.result.toString().replace(/^#/,"");return m(t,e.generalErrorReports)}}function m(e,t){var n;if(t&&t[e]){var r=t[e];if(r.brief&&r.explanation){n={title:r.brief.toString(),message:r.explanation.toString()};if(r.options&&r.options.length){n.options=[];for(var i=0;i<r.options.length;++i)if(r.options[i].label!=undefined){var s={label:r.options[i].label};r.options[i].uri&&r.options[i].action==="www"&&(s.url=r.options[i].uri),n.options.push(s)}}}}return n}var n,r,i,s,o,u,a;this.getValidationResults=p,this.isValid=d,this.needToRefreshAccessToken=h,this.getCustomError=m,f()};