From 4b8e2fc1d4323b0ed52a741233f8faf0ebf8674e Mon Sep 17 00:00:00 2001 From: djohalo2 Date: Mon, 24 Aug 2026 09:50:02 +0200 Subject: [PATCH] fix: hubspot plugin handle missing authors --- plugins/hubspot/src/PluginError.ts | 3 ++- plugins/hubspot/src/api.ts | 21 +++++++++++++++------ plugins/hubspot/src/blog.ts | 10 ++++++++-- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/plugins/hubspot/src/PluginError.ts b/plugins/hubspot/src/PluginError.ts index 84c18ff88..9d3c38b45 100644 --- a/plugins/hubspot/src/PluginError.ts +++ b/plugins/hubspot/src/PluginError.ts @@ -1,7 +1,8 @@ export class PluginError extends Error { constructor( public title: string, - message: string + message: string, + public status?: number ) { super(message) Object.setPrototypeOf(this, PluginError.prototype) diff --git a/plugins/hubspot/src/api.ts b/plugins/hubspot/src/api.ts index c8654fc72..47e0ddf58 100644 --- a/plugins/hubspot/src/api.ts +++ b/plugins/hubspot/src/api.ts @@ -149,7 +149,7 @@ const request = async ({ path, method, query, body }: RequestOptions): Promise => { - return cachedFetch( - queryKeys.blogAuthor(authorId), - () => request({ path: `/cms/v3/blogs/authors/${authorId}` }) as Promise - ) +export async function fetchBlogAuthor(authorId: string): Promise { + try { + return await cachedFetch( + queryKeys.blogAuthor(authorId), + () => + request({ + path: `/cms/v3/blogs/authors/${authorId}`, + query: { archived: "true" }, + }) as Promise + ) + } catch (e) { + if (e instanceof PluginError && e.status === 404) return undefined + throw e + } } export const fetchPublishedTables = (limit: number): Promise> => { diff --git a/plugins/hubspot/src/blog.ts b/plugins/hubspot/src/blog.ts index 8fc2871fb..b18930b85 100644 --- a/plugins/hubspot/src/blog.ts +++ b/plugins/hubspot/src/blog.ts @@ -251,8 +251,14 @@ export async function syncBlogs({ fields, includedFieldIds }: SyncBlogMutation) const authorNamesById = new Map() if (hasAuthorNameField) { - const authorIds = Array.from(new Set(posts.map(post => post.blogAuthorId))) - const authors = authorIds.length ? await Promise.all(authorIds.map(fetchBlogAuthor)) : [] + // Blog posts should have a blogAuthorId, but drafts or unexpected data may not. + // Gracefully fall back to the last updated author name in those cases. + const authorIds = Array.from( + new Set( + posts.map(post => post.blogAuthorId).filter((id): id is string => typeof id === "string" && id !== "") + ) + ) + const authors = authorIds.length ? (await Promise.all(authorIds.map(fetchBlogAuthor))).filter(isDefined) : [] for (const author of authors) { authorNamesById.set(author.id, author.displayName)