mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Handled bad URLs in oembed bookmark API
fixes #11636 - malformed URLs passed to oembed API would cause `got` or `metascraper` to throw an error and this would result in a 500 error from Ghost - this commit catches the errors and returns a reasonable response
This commit is contained in:
parent
f7bc233f4c
commit
a851cdfc7b
1 changed files with 17 additions and 9 deletions
|
@ -16,15 +16,22 @@ async function fetchBookmarkData(url, html) {
|
|||
require('metascraper-logo')()
|
||||
]);
|
||||
|
||||
if (!html) {
|
||||
const response = await request(url, {
|
||||
headers: {
|
||||
'user-agent': 'Ghost(https://github.com/TryGhost/Ghost)'
|
||||
}
|
||||
});
|
||||
html = response.body;
|
||||
let scraperResponse;
|
||||
|
||||
try {
|
||||
if (!html) {
|
||||
const response = await request(url, {
|
||||
headers: {
|
||||
'user-agent': 'Ghost(https://github.com/TryGhost/Ghost)'
|
||||
}
|
||||
});
|
||||
html = response.body;
|
||||
}
|
||||
scraperResponse = await metascraper({html, url});
|
||||
} catch (e) {
|
||||
return Promise.reject();
|
||||
}
|
||||
const scraperResponse = await metascraper({html, url});
|
||||
|
||||
const metadata = Object.assign({}, scraperResponse, {
|
||||
thumbnail: scraperResponse.image,
|
||||
icon: scraperResponse.logo
|
||||
|
@ -132,7 +139,8 @@ module.exports = {
|
|||
let {url, type} = data;
|
||||
|
||||
if (type === 'bookmark') {
|
||||
return fetchBookmarkData(url);
|
||||
return fetchBookmarkData(url)
|
||||
.catch(() => unknownProvider(url));
|
||||
}
|
||||
|
||||
return fetchOembedData(url).then((response) => {
|
||||
|
|
Loading…
Add table
Reference in a new issue