diff --git a/README.md b/README.md index cb44e1f..15309bf 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,12 @@ The exported property contains an array of definitions, each linking a match to - `options.gracePeriod`: Only send the response after a certain amount of time. This will group changes in the future. - `options.ignoreFromSelf`: Don't inform about changes that originated from the microservice to be informed (based on the hostname). +### Ignoring errors: + +Some errors can be ignored, the configuration for it is the following: + +- `IGNORE_UNREACHABLE_SERVICES`: a comma-separated list of service names for which the unreachable error should be ignored + ## Delta formats The delta may be offered in multiple formats. Versions should match the exact string. Specify `options.resourceFormat` to indicate the specific resourceformat. diff --git a/app.js b/app.js index dab86bd..04c4a60 100644 --- a/app.js +++ b/app.js @@ -16,6 +16,8 @@ app.use( bodyParser.json( { if( process.env["LOG_SERVER_CONFIGURATION"] ) console.log(JSON.stringify( services )); +let ignore_unreachable_services = (process.env["IGNORE_UNREACHABLE_SERVICES"]||"").split(','); + app.get( '/', function( req, res ) { res.status(200); res.send("Hello, delta notification is running"); @@ -53,8 +55,21 @@ async function informWatchers( changeSets, res, muCallIdTrail, muSessionId ){ console.log(`Checking if we want to send to ${entry.callback.url}`); const matchSpec = entry.match; + let originFilteredChangeSets = []; + + try { + originFilteredChangeSets = await filterMatchesForOrigin(changeSets, entry) + } catch (error) { + // When there's an error, this means the callback url could not be resolved and thus this should be handled + let hostname = (new URL(entry.callback.url)).hostname; + if (ignore_unreachable_services.filter(a => a === hostname).length === 0) { + console.error(`Error happened while filtering, ${hostname} couldn't be resolved`) + console.error(`please check that the service is running and the configuration file is correct`) + console.error(error) + } + return + } - const originFilteredChangeSets = await filterMatchesForOrigin( changeSets, entry ); if( process.env["DEBUG_TRIPLE_MATCHES_SPEC"] && entry.options.ignoreFromSelf ) console.log(`There are ${originFilteredChangeSets.length} changes sets not from ${hostnameForEntry( entry )}`);