From 7d9721dd54459dd517028f19413a460240debad5 Mon Sep 17 00:00:00 2001 From: Thibaut Patel Date: Wed, 1 Dec 2021 17:46:19 +0100 Subject: [PATCH] Added one error catching inside the oembed service refs https://github.com/TryGhost/Team/issues/1200 - The error was fixed in https://github.com/TryGhost/Ghost/commit/a1421c2380d742f5e9b301901e4f78daee9aa00e - The error catching prevents future 500 errors in the API - The logging enable visibility on these errors to fix them if they happen --- core/server/services/oembed.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/core/server/services/oembed.js b/core/server/services/oembed.js index 3b72ab9daa..3317a221d3 100644 --- a/core/server/services/oembed.js +++ b/core/server/services/oembed.js @@ -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,