diff --git a/sanitizer/PeliasServiceError.js b/sanitizer/PeliasServiceError.js new file mode 100644 index 000000000..3fad75868 --- /dev/null +++ b/sanitizer/PeliasServiceError.js @@ -0,0 +1,15 @@ +class PeliasServiceError extends Error { + constructor(message = '') { + super(message); + } + + toString() { + return this.message; + } + + toJSON() { + return this.message; + } +} + +module.exports = PeliasServiceError; diff --git a/sanitizer/sanitizeAll.js b/sanitizer/sanitizeAll.js index 50bff0146..c35b3133a 100644 --- a/sanitizer/sanitizeAll.js +++ b/sanitizer/sanitizeAll.js @@ -1,9 +1,12 @@ const PeliasParameterError = require('./PeliasParameterError'); const PeliasTimeoutError = require('../sanitizer/PeliasTimeoutError'); +const PeliasServiceError = require('../sanitizer/PeliasServiceError'); function getCorrectErrorType(message) { - if (message.includes( 'Timeout')) { + if (message.includes('Timeout') || message.includes('timeout')) { return new PeliasTimeoutError(message); + } else if (message.includes('Parse') || message.includes('parse') || message.includes('connect') || message.includes('ECONN')) { + return new PeliasServiceError(message); } // most errors are parameter errors