From 4bb99d90a5ef9e64ef147885ab3c66d1b37ed057 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Tue, 28 Apr 2020 11:22:58 -0700 Subject: [PATCH] Handle forwarded errors from noembed.com. #2327 --- src/Linkification/Embedding.coffee | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Linkification/Embedding.coffee b/src/Linkification/Embedding.coffee index 375785cc0..5ee6a1583 100644 --- a/src/Linkification/Embedding.coffee +++ b/src/Linkification/Embedding.coffee @@ -177,12 +177,15 @@ Embedding = $.toggleClass @, 'embed-removed' title: (req, data) -> - return unless req.status - {key, uid, options, link, post} = data - {status} = req service = Embedding.types[key].title + {status} = req + if status in [200, 304] and service.status + status = service.status(req.response)[0] + + return unless status + text = "[#{key}] #{switch status when 200, 304 text = service.text req.response, uid @@ -507,6 +510,12 @@ Embedding = title: api: (uid) -> "https://noembed.com/embed?url=https%3A//www.youtube.com/watch%3Fv%3D#{uid}&format=json" text: (_) -> _.title + status: (_) -> + if _.error + m = _.error.match(/^(\d*)\s*(.*)/) + [+m[1], m[2]] + else + [200, 'OK'] preview: url: (uid) -> "https://img.youtube.com/vi/#{uid}/0.jpg" height: 360