mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-27 18:52:14 +03:00
Refactored oembed service to async/await syntax
no issue - The method was super hard to read with unintuitive catches in multiple places and lots of conditional logic. There's still more to reshuffle here, but that would be for the next time. At least now the data flow is clear within the method
This commit is contained in:
parent
0703596ace
commit
04e7c9fca5
@ -155,7 +155,7 @@ class OEmbed {
|
||||
|
||||
/**
|
||||
* @param {string} _url
|
||||
* @param {string} cardType
|
||||
* @param {string} [cardType]
|
||||
*
|
||||
* @returns {Promise<Object>}
|
||||
*/
|
||||
@ -267,22 +267,27 @@ class OEmbed {
|
||||
* @returns {Promise<Object>}
|
||||
*/
|
||||
async fetchOembedDataFromUrl(url, type) {
|
||||
if (type === 'bookmark') {
|
||||
return this.fetchBookmarkData(url)
|
||||
.catch(this.errorHandler(url));
|
||||
}
|
||||
let data;
|
||||
|
||||
return this.fetchOembedData(url).then((response) => {
|
||||
if (!response && !type) {
|
||||
try {
|
||||
if (type === 'bookmark') {
|
||||
return this.fetchBookmarkData(url);
|
||||
}
|
||||
return response;
|
||||
}).then((response) => {
|
||||
if (!response) {
|
||||
return this.unknownProvider(url);
|
||||
|
||||
data = await this.fetchOembedData(url);
|
||||
|
||||
if (!data && !type) {
|
||||
data = await this.fetchBookmarkData(url);
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
data = await this.unknownProvider(url);
|
||||
}
|
||||
|
||||
return data;
|
||||
} catch (e) {
|
||||
return this.errorHandler(url);
|
||||
}
|
||||
return response;
|
||||
}).catch(this.errorHandler(url));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user