From f2a9c02af7bfed58cf2f1904e92f96c47f201efe Mon Sep 17 00:00:00 2001 From: Southpaw Date: Sat, 26 Aug 2023 10:39:21 +0100 Subject: [PATCH] Catch error if Ghost API request fails --- src/methods/publishPost.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/methods/publishPost.ts b/src/methods/publishPost.ts index aa6fac6..a675a7a 100644 --- a/src/methods/publishPost.ts +++ b/src/methods/publishPost.ts @@ -47,7 +47,7 @@ export const publishPost = async ( excerpt: metaMatter?.excerpt || undefined, feature_image: metaMatter?.feature_image || undefined, }; - + try{ const result = await requestUrl({ url: `${settings.url}/ghost/api/${version}/admin/posts/?source=html`, method: "POST", @@ -58,7 +58,7 @@ export const publishPost = async ( Authorization: `Ghost ${token}`, }, body: JSON.stringify(contentPost(frontmatter, data)), - }); + }) const json = result.json; @@ -74,4 +74,8 @@ export const publishPost = async ( } return json; -}; +} catch (error: any) { + new Notice(`Couldn't connect to the Ghost API. Is the API URL and Admin API Key correct? + +${error.name}: ${error.message}`) +}};