Skip to content

πŸ“¨ The ultimate agentic social media scheduling tool πŸ€–

fix(calendar): curate post errors at read time instead of write time

Gilad Resisic8bf9d8f4259
diff --git a/apps/frontend/src/components/launches/calendar.tsx b/apps/frontend/src/components/launches/calendar.tsx
index fe01e2b85..2616c08fd 100644
--- a/apps/frontend/src/components/launches/calendar.tsx
+++ b/apps/frontend/src/components/launches/calendar.tsx
@@ -59,21 +59,6 @@ import { stripHtmlValidation } from '@gitroom/helpers/utils/strip.html.validatio
import { newDayjs } from '@gitroom/frontend/components/layout/set.timezone';
import { Button } from '@gitroom/react/form/button';
-// Curated provider errors are stored as {"message":"..."} β€” anything else in
-// post.error (internal strings like 'Refresh channel needed', serialized
-// failures from before curation existed) falls back to the generic tooltip
-const displayErrorMessage = (error?: string | null) => {
- if (!error) {
- return null;
- }
- try {
- const parsed = JSON.parse(error);
- return typeof parsed?.message === 'string' ? parsed.message : null;
- } catch (e) {
- return null;
- }
-};
-
// Extend dayjs with necessary plugins
extend(isSameOrAfter);
extend(isSameOrBefore);
@@ -1075,7 +1060,7 @@ const CalendarItem: FC<{
className="absolute -top-[6px] -left-[6px] z-20 w-[18px] h-[18px] rounded-full bg-red-500 flex items-center justify-center text-white text-[11px] font-bold cursor-pointer"
data-tooltip-id="tooltip"
data-tooltip-class-name="!max-w-[400px] break-words"
- data-tooltip-content={displayErrorMessage(post.error) || 'An error occurred while publishing this post'}
+ data-tooltip-content={post.error || 'An error occurred while publishing this post'}
>
!
</div>
diff --git a/libraries/nestjs-libraries/src/database/prisma/posts/posts.repository.ts b/libraries/nestjs-libraries/src/database/prisma/posts/posts.repository.ts
index bce687e07..17223e6eb 100644
--- a/libraries/nestjs-libraries/src/database/prisma/posts/posts.repository.ts
+++ b/libraries/nestjs-libraries/src/database/prisma/posts/posts.repository.ts
@@ -126,6 +126,32 @@ export class PostsRepository {
});
}
+ // Post.error persists the raw serialized workflow failure; only curated
+ // provider messages are surfaced to the calendar and the public API β€”
+ // bad_body failures whose message came from a provider handleErrors
+ // mapping or a hand-written provider throw (unmapped API responses carry
+ // the 'Unknown Error' placeholder instead). Internal debug strings (e.g.
+ // 'Refresh channel needed') and unmapped failures come out as null.
+ private curatedError(error?: string | null): string | null {
+ if (!error) {
+ return null;
+ }
+ try {
+ const parsed = JSON.parse(error);
+ const [type, message] = parsed?.cause?.failure?.message
+ ? [parsed?.cause?.type, parsed?.cause?.failure?.message]
+ : [
+ parsed?.failure?.cause?.applicationFailureInfo?.type,
+ parsed?.failure?.cause?.message,
+ ];
+ return type === 'bad_body' && message && message !== 'Unknown Error'
+ ? message
+ : null;
+ } catch (err) {
+ return null;
+ }
+ }
+
async getPosts(orgId: string, query: GetPostsDto) {
// Use the provided start and end dates directly
const startDate = dayjs.utc(query.startDate).toDate();
@@ -193,7 +219,9 @@ export class PostsRepository {
},
});
- return list.reduce((all, post) => {
+ return list
+ .map((post) => ({ ...post, error: this.curatedError(post.error) }))
+ .reduce((all, post) => {
if (!post.intervalInDays) {
return [...all, post];
}
@@ -412,37 +440,15 @@ export class PostsRepository {
}
async changeState(id: string, state: State, err?: any, body?: any) {
- // The calendar tooltip only surfaces curated provider messages: bad_body
- // failures whose message came from a handleErrors mapping or a
- // hand-written provider throw (unmapped API responses carry the
- // 'Unknown Error' placeholder instead). Those are stored as
- // {"message":"..."} so the frontend can tell them apart from everything
- // this column held until now (internal strings like 'Refresh channel
- // needed', serialized failures), which keeps rendering the generic
- // tooltip. Internal strings are still stored for debugging, and the full
- // failure is kept in the Errors table below.
- const failureMessage =
- err?.cause?.failure?.message || err?.failure?.cause?.message;
- const errorMessage = !err
- ? undefined
- : typeof err === 'string'
- ? err // stored for debugging, rendered as the generic tooltip
- : err?.cause?.type === 'bad_body' &&
- failureMessage &&
- failureMessage !== 'Unknown Error'
- ? JSON.stringify({ message: failureMessage })
- : undefined;
-
const update = await this._post.model.post.update({
where: {
id,
},
data: {
state,
- // Always overwrite on a new failure - keeping the previous value would
- // show a stale (and now wrong) message for a post that failed again
- // for a different reason.
- ...(err ? { error: errorMessage ?? null } : {}),
+ ...(err
+ ? { error: typeof err === 'string' ? err : JSON.stringify(err) }
+ : {}),
},
include: {
integration: {