Skip to content

Commit aab1d24

Browse files
committed
fix(uploads): return retryable 409 for not-ready docs in slack/teams sends
The slack send-message and teams write_channel/write_chat routes call download helpers that can throw DocCompileUserError while a generated doc is still compiling. Map it to the shared docNotReadyResponse 409 (matching the other migrated tool routes) instead of a generic 500. The provider attachment path is internal LLM execution (no HTTP response), so it intentionally propagates the typed error.
1 parent 3e7d589 commit aab1d24

3 files changed

Lines changed: 9 additions & 0 deletions

File tree

apps/sim/app/api/tools/microsoft_teams/write_channel/route.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { checkInternalAuth } from '@/lib/auth/hybrid'
77
import { secureFetchWithValidation } from '@/lib/core/security/input-validation.server'
88
import { generateRequestId } from '@/lib/core/utils/request'
99
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
10+
import { docNotReadyResponse } from '@/lib/uploads/utils/servable-file-response'
1011
import { FileAccessDeniedError } from '@/app/api/files/authorization'
1112
import { uploadFilesForTeamsMessage } from '@/tools/microsoft_teams/server-utils'
1213
import type { GraphApiErrorResponse, GraphChatMessage } from '@/tools/microsoft_teams/types'
@@ -167,6 +168,8 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
167168
if (error instanceof FileAccessDeniedError) {
168169
return NextResponse.json({ success: false, error: 'File not found' }, { status: 404 })
169170
}
171+
const notReady = docNotReadyResponse(error)
172+
if (notReady) return notReady
170173
logger.error(`[${requestId}] Error sending Teams channel message:`, error)
171174
return NextResponse.json(
172175
{

apps/sim/app/api/tools/microsoft_teams/write_chat/route.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { checkInternalAuth } from '@/lib/auth/hybrid'
77
import { secureFetchWithValidation } from '@/lib/core/security/input-validation.server'
88
import { generateRequestId } from '@/lib/core/utils/request'
99
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
10+
import { docNotReadyResponse } from '@/lib/uploads/utils/servable-file-response'
1011
import { FileAccessDeniedError } from '@/app/api/files/authorization'
1112
import { uploadFilesForTeamsMessage } from '@/tools/microsoft_teams/server-utils'
1213
import type { GraphApiErrorResponse, GraphChatMessage } from '@/tools/microsoft_teams/types'
@@ -164,6 +165,8 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
164165
if (error instanceof FileAccessDeniedError) {
165166
return NextResponse.json({ success: false, error: 'File not found' }, { status: 404 })
166167
}
168+
const notReady = docNotReadyResponse(error)
169+
if (notReady) return notReady
167170
logger.error(`[${requestId}] Error sending Teams chat message:`, error)
168171
return NextResponse.json(
169172
{

apps/sim/app/api/tools/slack/send-message/route.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { parseRequest } from '@/lib/api/server'
66
import { checkInternalAuth } from '@/lib/auth/hybrid'
77
import { generateRequestId } from '@/lib/core/utils/request'
88
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
9+
import { docNotReadyResponse } from '@/lib/uploads/utils/servable-file-response'
910
import { FileAccessDeniedError } from '@/app/api/files/authorization'
1011
import { sendSlackMessage } from '@/app/api/tools/slack/utils'
1112

@@ -72,6 +73,8 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
7273
if (error instanceof FileAccessDeniedError) {
7374
return NextResponse.json({ success: false, error: 'File not found' }, { status: 404 })
7475
}
76+
const notReady = docNotReadyResponse(error)
77+
if (notReady) return notReady
7578
logger.error(`[${requestId}] Error sending Slack message:`, error)
7679
return NextResponse.json(
7780
{

0 commit comments

Comments
 (0)