Name
sn_ibm_trans_spoke.IBMTranslationErrorHandler
Description
All the Error handling methods related to IBM Translation actions
Script
var IBMTranslationErrorHandler = Class.create();
IBMTranslationErrorHandler.prototype = {
initialize: function() {},
detectLanguageHandler: function(errorMessage) {
var standardErrorCode = this.mapDetectLanguageErrorCode(errorMessage);
var standardErrorMessage = this.mapErrorMessage(standardErrorCode, errorMessage);
return {
'errorCode': standardErrorCode,
'errorMessage': standardErrorMessage
};
},
translateTextHandler: function(errorMessage) {
var standardErrorCode = this.mapTranslateTextErrorCode(errorMessage);
var standardErrorMessage = this.mapErrorMessage(standardErrorCode, errorMessage);
return {
'errorCode': standardErrorCode,
'errorMessage': standardErrorMessage
};
},
mapDetectLanguageErrorCode: function(errorMessage) {
if (errorMessage) {
switch (true) {
// Exceeded max content length for translate request, max allowed is 50 KiB.
case /(max)+.*(request)+/i.test(errorMessage):
return '40052';
// Unauthorized
case /(unauthorized|Forbidden)/i.test(errorMessage):
return '40055';
// Please visit your IBM Cloud Catalog page to update your credentials. Deprecation of legacy credentials was announced 1 year ago. For more information please visit: https://medium.com/ibm-watson/identity-and-access-management-updates-for-watson-services-12b6344b9cf
case /(update your credentials)/i.test(errorMessage):
return '40055';
default:
return '40050';
}
} else {
return '40051';
}
},
mapTranslateTextErrorCode: function(errorMessage) {
if (errorMessage) {
switch (true) {
// Exceeded max content length for translate request, max allowed is 50 KiB.
case /(max)+.*(request)+/i.test(errorMessage):
return '40052';
// Given source language is not supported: xyz | The parameter 'source' should not be empty
case /(source)+.*(not)+.*((supported)|(empty))+/i.test(errorMessage):
return '40053';
// Given target language is not supported: xyz | The parameter 'target' should not be empty
case /(target)+.*(not)+.*((supported)|(empty))+/i.test(errorMessage):
return '40054';
// Unauthorized
case /(unauthorized|Forbidden)/i.test(errorMessage):
return '40055';
// Please visit your IBM Cloud Catalog page to update your credentials. Deprecation of legacy credentials was announced 1 year ago. For more information please visit: https://medium.com/ibm-watson/identity-and-access-management-updates-for-watson-services-12b6344b9cf
case /(update your credentials)/i.test(errorMessage):
return '40055';
// Model not found.
case /(model)+.*(not)+.*/i.test(errorMessage):
return '40056';
// Unable to find model for specified languages
case /(unable).*(find).*(model).*(languages)/i.test(errorMessage):
return '40056';
default:
return '40050';
}
} else {
return '40051';
}
},
mapErrorMessage: function(errorCode, errorMessage) {
if (errorCode) {
switch (errorCode) {
case '40051':
return gs.getMessage('Unknown error occurred');
case '40052':
return gs.getMessage('Text has exceeded its maximum length');
case '40053':
return gs.getMessage('Source language is invalid');
case '40054':
return gs.getMessage('Target language is invalid');
case '40055':
return gs.getMessage('Request is not authorized because credentials are missing or invalid');
case '40056':
return gs.getMessage('Text cannot be translated to target languages');
default:
return gs.getMessage(errorMessage);
}
} else {
return gs.getMessage('Unknown error occurred');
}
},
getTimeoutValue: function() {
return parseInt(gs.getProperty('glide.dynamic.translation.default.timeout', 40000));
},
type: 'IBMTranslationErrorHandler'
};
Sys ID
d9943aa2b7e0330030e88c28ee11a974