Better error handling for mercury reader.

This commit is contained in:
Samuel Clay 2021-10-26 08:15:05 -04:00
parent bf70f2aaf7
commit c9075cc151
3 changed files with 12 additions and 1 deletions

View file

@ -40,7 +40,7 @@ if ENV_PROD
app.get "/debug", (req, res) ->
throw new Error("Debugging Sentry")
app.use(Sentry.Handlers.errorHandler())
app.use Sentry.Handlers.errorHandler()
log.debug "Setting up Sentry debugging: #{process.env.SENTRY_DSN.substr(0, 20)}..."
log.debug "Starting NewsBlur Node Server: #{process.env.SERVER_NAME || 'localhost'}"

View file

@ -31,5 +31,10 @@ original_text = (app) =>
Mercury.parse(url).then (result) =>
log.debug "Fetched: #{url}"
res.end JSON.stringify result
.catch (error) =>
log.debug "Failed to fetch: #{url}: #{error}"
throw new Error("Failed to fetch: #{url}: #{error}")
return res.end JSON.stringify error: "Failed to fetch #{url}: #{error}"
exports.original_text = original_text

View file

@ -41,6 +41,12 @@
return Mercury.parse(url).then((result) => {
log.debug(`Fetched: ${url}`);
return res.end(JSON.stringify(result));
}).catch((error) => {
log.debug(`Failed to fetch: ${url}: ${error}`);
throw new Error(`Failed to fetch: ${url}: ${error}`);
return res.end(JSON.stringify({
error: `Failed to fetch ${url}: ${error}`
}));
});
});
};