Skip to content

Commit 0147ffc

Browse files
committed
fix(uploads): surface server error message and bypass quota for local-storage fallback
1 parent 681e1d7 commit 0147ffc

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

apps/sim/app/api/workspaces/[id]/files/presigned/route.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,6 @@ export const POST = withRouteHandler(
4646
)
4747
}
4848

49-
const quotaCheck = await checkStorageQuota(userId, fileSize)
50-
if (!quotaCheck.allowed) {
51-
return NextResponse.json(
52-
{ error: quotaCheck.error || 'Storage limit exceeded' },
53-
{ status: 413 }
54-
)
55-
}
56-
5749
if (!hasCloudStorage()) {
5850
logger.info(`Local storage detected, signaling API fallback for ${fileName}`)
5951
return NextResponse.json({
@@ -64,6 +56,14 @@ export const POST = withRouteHandler(
6456
})
6557
}
6658

59+
const quotaCheck = await checkStorageQuota(userId, fileSize)
60+
if (!quotaCheck.allowed) {
61+
return NextResponse.json(
62+
{ error: quotaCheck.error || 'Storage limit exceeded' },
63+
{ status: 413 }
64+
)
65+
}
66+
6767
const key = generateWorkspaceFileKey(workspaceId, fileName)
6868
const presigned = await generatePresignedUploadUrl({
6969
fileName,

apps/sim/lib/uploads/client/direct-upload.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,15 @@ export const getPresignedUploadInfo = async (
180180
try {
181181
errorDetails = await response.json()
182182
} catch {}
183+
const serverMessage =
184+
errorDetails != null &&
185+
typeof errorDetails === 'object' &&
186+
typeof (errorDetails as Record<string, unknown>).error === 'string'
187+
? ((errorDetails as Record<string, unknown>).error as string)
188+
: null
183189
throw new DirectUploadError(
184-
`Failed to get presigned URL for ${file.name}: ${response.status} ${response.statusText}`,
190+
serverMessage ||
191+
`Failed to get presigned URL for ${file.name}: ${response.status} ${response.statusText}`,
185192
'PRESIGNED_URL_ERROR',
186193
errorDetails
187194
)

0 commit comments

Comments
 (0)