const errorList = { // { name : message } UnsupportedProtocolError: 'Protocole du webservice ADD-UNPAYWALL non pris en charge', HTTPError: 'Erreur HTTP du webservice ADD-UNPAYWALL', ParseError: 'Erreur du parsing de résultat du webservice ADD-UNPAYWALL', FetchError: 'Erreur dans la requête du webservice ADD-UNPAYWALL', TimeoutError: 'Erreur de Timeout dans la requête du webservice ADD-UNPAYWALL', CancelError: 'La requête du webservice ADD-UNPAYWALL a été annulée', BadResponse: 'Le webservice ADD-UNPAYWALL renvoie une réponse incorrecte' }; /** * Creates the `Error` instance the pass to doTheJob's callback. * @param {object} docObject The `docObject` provided by the previous module. * @param {string} errName The name of the `Error` instance. * @returns {Error} The new `Error` instance or the original one if it was provided. */ function handleError (docObject, error) { // Looks for the appropriate error handler const errName = error.name; let errorMsg = errorList[errName]; if (!errorMsg) { docObject.errCode = errName; } else { docObject.errCode = docObject._errMsg = errorMsg = errName; } docObject.errMessage = error.message+"\n"+error.stack; const finalError = new Error(errorMsg); finalError.nonBlocking = true; return new Error(finalError); } module.exports = handleError;