Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve service error handling #1664

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading