0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00

Added one error catching inside the oembed service

refs https://github.com/TryGhost/Team/issues/1200

- The error was fixed in a1421c2380
- The error catching prevents future 500 errors in the API
- The logging enable visibility on these errors to fix them if they happen
This commit is contained in:
Thibaut Patel 2021-12-01 17:46:19 +01:00
parent 8814f7a638
commit 7d9721dd54

View file

@ -1,6 +1,7 @@
const errors = require('@tryghost/errors');
const tpl = require('@tryghost/tpl');
const logging = require('@tryghost/logging');
const sentry = require('../../shared/sentry');
const {extract, hasProvider} = require('oembed-parser');
const cheerio = require('cheerio');
const _ = require('lodash');
@ -128,7 +129,14 @@ class OEmbed {
const response = await this.externalRequest(url, {cookieJar});
const html = response.body;
scraperResponse = await metascraper({html, url});
try {
scraperResponse = await metascraper({html, url});
} catch (err) {
// Log to avoid being blind to errors happenning in metascraper
sentry.captureException(err);
logging.error(err);
return this.unknownProvider(url);
}
const metadata = Object.assign({}, scraperResponse, {
thumbnail: scraperResponse.image,