Skip to content

Commit

Permalink
feat(errors): improve service error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ianthetechie authored and missinglink committed Nov 29, 2023
1 parent 9a0e94f commit df7af02
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
15 changes: 15 additions & 0 deletions sanitizer/PeliasServiceError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class PeliasServiceError extends Error {
constructor(message = '') {
super(message);
}

toString() {
return this.message;
}

toJSON() {
return this.message;
}
}

module.exports = PeliasServiceError;
5 changes: 4 additions & 1 deletion sanitizer/sanitizeAll.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit df7af02

Please sign in to comment.