Skip to content

Commit 8bb8551

Browse files
committed
feat: actionable error messages — overhaul friendlyCalcomError, consolidate CalcomApiError handling via deps
1 parent 5e08588 commit 8bb8551

2 files changed

Lines changed: 26 additions & 15 deletions

File tree

apps/chat/lib/bot.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -426,24 +426,34 @@ function isSlackAuthError(err: unknown): boolean {
426426
return false;
427427
}
428428

429-
function friendlyCalcomError(err: CalcomApiError): string {
429+
function friendlyCalcomError(err: CalcomApiError, context?: string): string {
430+
const apiDetail = err.message && !err.message.startsWith("Cal.com API error:")
431+
? ` (${err.message})`
432+
: "";
433+
430434
switch (err.statusCode) {
431435
case 400:
432-
case 422:
433-
return "The request was invalid. Please check the details and try again.";
436+
return `The request had invalid data${apiDetail}. Please check the details and try again.`;
434437
case 401:
435438
case 403:
436-
return "Your Cal.com session has expired. Please reconnect your account.";
439+
return "Your Cal.com session has expired. Please reconnect your account to continue.";
437440
case 404:
438-
return "The booking or event type was not found.";
441+
return `The requested resource was not found${apiDetail}. It may have been deleted or the ID is incorrect.`;
439442
case 409:
440-
return "This time slot is no longer available.";
443+
return context === "booking"
444+
? "This time slot is no longer available \u2014 someone else may have just booked it. Would you like me to check for other available times?"
445+
: `There was a conflict${apiDetail}. The resource may have been modified. Please try again.`;
446+
case 422:
447+
return `The request was missing required information${apiDetail}. Please provide all required fields and try again.`;
441448
case 429:
442-
return "Cal.com rate limit reached. Please try again in a moment.";
449+
return "Cal.com's rate limit has been reached. Please wait about 30 seconds and try again.";
443450
default:
444-
return err.statusCode && err.statusCode >= 500
445-
? "Cal.com is experiencing issues. Please try again later."
446-
: "Something went wrong with the Cal.com API. Please try again.";
451+
if (err.statusCode && err.statusCode >= 500) {
452+
return err.code === "FETCH_RETRY_EXHAUSTED"
453+
? "Cal.com is not responding after multiple attempts. The service may be temporarily down \u2014 please try again in a few minutes."
454+
: "Cal.com is experiencing issues right now. Please try again in a moment.";
455+
}
456+
return `Something went wrong with the Cal.com API${apiDetail}. Please try again.`;
447457
}
448458
}
449459

@@ -1126,4 +1136,5 @@ registerSlackHandlers(bot, getSlackAdapter, {
11261136
extractTeamIdFromRaw,
11271137
buildHistory,
11281138
makeLookupSlackUser,
1139+
friendlyCalcomError,
11291140
});

apps/chat/lib/handlers/slack.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export interface RegisterSlackHandlersDeps {
9090
extractTeamIdFromRaw: (raw: unknown, adapterName?: string) => string;
9191
buildHistory: (thread: Thread) => Promise<ModelMessage[]>;
9292
makeLookupSlackUser: (teamId: string) => LookupPlatformUserFn;
93+
friendlyCalcomError: (err: import("../calcom/client").CalcomApiError, context?: string) => string;
9394
}
9495

9596
function oauthLinkMessage(platform: string, teamId: string, userId: string) {
@@ -119,6 +120,7 @@ export function registerSlackHandlers(
119120
extractTeamIdFromRaw,
120121
buildHistory,
121122
makeLookupSlackUser,
123+
friendlyCalcomError,
122124
} = deps;
123125

124126
async function safeChannelPost(
@@ -583,7 +585,7 @@ export function registerSlackHandlers(
583585
if (isAIToolCallError(lastStreamErrorRef.current))
584586
return "I had trouble processing that request. Please try again, or be more specific (e.g. run /cal bookings first, then cancel by booking ID).";
585587
if (lastStreamErrorRef.current instanceof CalcomApiError)
586-
return `The request failed: ${lastStreamErrorRef.current.statusCode === 401 || lastStreamErrorRef.current.statusCode === 403 ? "Your Cal.com session has expired. Please reconnect your account." : lastStreamErrorRef.current.statusCode === 429 ? "Cal.com rate limit reached. Please try again in a moment." : "Something went wrong with the Cal.com API. Please try again."}`;
588+
return friendlyCalcomError(lastStreamErrorRef.current);
587589
if (isSlackAuthError(err))
588590
return "Sorry, something went wrong while processing your request. Please try again.";
589591
return undefined;
@@ -940,9 +942,7 @@ export function registerSlackHandlers(
940942
logContext: "confirm_booking",
941943
getCustomErrorMessage: (err) => {
942944
if (err instanceof CalcomApiError) {
943-
if (err.statusCode === 409) return "This time slot is no longer available. Please pick another.";
944-
if (err.statusCode === 422) return "The booking details are incomplete. Please try again.";
945-
return "Failed to create the booking. Please try again.";
945+
return friendlyCalcomError(err, "booking");
946946
}
947947
return err instanceof Error ? "Failed to create the booking. Please try again." : undefined;
948948
},
@@ -1005,7 +1005,7 @@ export function registerSlackHandlers(
10051005
if (isAIToolCallError(lastStreamErrorRef.current))
10061006
return "I had trouble processing that request. Please try again, or be more specific (e.g. run /cal bookings first, then cancel by booking ID).";
10071007
if (lastStreamErrorRef.current instanceof CalcomApiError)
1008-
return `The request failed: ${lastStreamErrorRef.current.statusCode === 401 || lastStreamErrorRef.current.statusCode === 403 ? "Your Cal.com session has expired. Please reconnect your account." : lastStreamErrorRef.current.statusCode === 429 ? "Cal.com rate limit reached. Please try again in a moment." : "Something went wrong with the Cal.com API. Please try again."}`;
1008+
return friendlyCalcomError(lastStreamErrorRef.current);
10091009
if (isSlackAuthError(err))
10101010
return "Sorry, something went wrong while processing your request. Please try again.";
10111011
return undefined;

0 commit comments

Comments
 (0)