From df7af02480c54a496f405b781c4831e579289190 Mon Sep 17 00:00:00 2001 From: Ian Wagner Date: Tue, 11 Apr 2023 23:31:41 +0900 Subject: [PATCH] feat(errors): improve service error handling --- sanitizer/PeliasServiceError.js | 15 +++++++++++++++ sanitizer/sanitizeAll.js | 5 ++++- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 sanitizer/PeliasServiceError.js 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