Skip to content

Commit d0d35dd

Browse files
waleedlatif1claude
andauthored
fix: address PR review comments (#4042)
* fix: address PR review comments on staging release - Add try/catch around clipboard.writeText() in CopyCodeButton - Add missing folder and past_chat cases in resolveResourceFromContext - Return 400 for ZodError instead of 500 in all 8 Athena API routes Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(api): return 400 for Zod validation errors across 27 API routes Routes using z.parse() were returning 500 for ZodError (client input validation failures). Added instanceof z.ZodError check to return 400 before the generic 500 handler, matching the established pattern used by 115+ other routes. Affected services: CloudWatch (7), CloudFormation (7), DynamoDB (6), Slack (3), Outlook (2), OneDrive (1), Google Drive (1). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(api): add success:false to ZodError responses for consistency 7 routes used { success: false, error: ... } in their generic error handler but our ZodError handler only returned { error: ... }. Aligned the ZodError response shape to match. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9282d1b commit d0d35dd

File tree

36 files changed

+218
-4
lines changed

36 files changed

+218
-4
lines changed

apps/sim/app/api/tools/athena/create-named-query/route.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ export async function POST(request: NextRequest) {
5555
},
5656
})
5757
} catch (error) {
58+
if (error instanceof z.ZodError) {
59+
return NextResponse.json(
60+
{ error: error.errors[0]?.message ?? 'Invalid request' },
61+
{ status: 400 }
62+
)
63+
}
5864
const errorMessage =
5965
error instanceof Error ? error.message : 'Failed to create Athena named query'
6066
logger.error('CreateNamedQuery failed', { error: errorMessage })

apps/sim/app/api/tools/athena/get-named-query/route.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ export async function POST(request: NextRequest) {
5353
},
5454
})
5555
} catch (error) {
56+
if (error instanceof z.ZodError) {
57+
return NextResponse.json(
58+
{ error: error.errors[0]?.message ?? 'Invalid request' },
59+
{ status: 400 }
60+
)
61+
}
5662
const errorMessage = error instanceof Error ? error.message : 'Failed to get Athena named query'
5763
logger.error('GetNamedQuery failed', { error: errorMessage })
5864
return NextResponse.json({ error: errorMessage }, { status: 500 })

apps/sim/app/api/tools/athena/get-query-execution/route.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ export async function POST(request: NextRequest) {
6363
},
6464
})
6565
} catch (error) {
66+
if (error instanceof z.ZodError) {
67+
return NextResponse.json(
68+
{ error: error.errors[0]?.message ?? 'Invalid request' },
69+
{ status: 400 }
70+
)
71+
}
6672
const errorMessage =
6773
error instanceof Error ? error.message : 'Failed to get Athena query execution'
6874
logger.error('GetQueryExecution failed', { error: errorMessage })

apps/sim/app/api/tools/athena/get-query-results/route.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ export async function POST(request: NextRequest) {
7474
},
7575
})
7676
} catch (error) {
77+
if (error instanceof z.ZodError) {
78+
return NextResponse.json(
79+
{ error: error.errors[0]?.message ?? 'Invalid request' },
80+
{ status: 400 }
81+
)
82+
}
7783
const errorMessage =
7884
error instanceof Error ? error.message : 'Failed to get Athena query results'
7985
logger.error('GetQueryResults failed', { error: errorMessage })

apps/sim/app/api/tools/athena/list-named-queries/route.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ export async function POST(request: NextRequest) {
5151
},
5252
})
5353
} catch (error) {
54+
if (error instanceof z.ZodError) {
55+
return NextResponse.json(
56+
{ error: error.errors[0]?.message ?? 'Invalid request' },
57+
{ status: 400 }
58+
)
59+
}
5460
const errorMessage =
5561
error instanceof Error ? error.message : 'Failed to list Athena named queries'
5662
logger.error('ListNamedQueries failed', { error: errorMessage })

apps/sim/app/api/tools/athena/list-query-executions/route.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ export async function POST(request: NextRequest) {
5151
},
5252
})
5353
} catch (error) {
54+
if (error instanceof z.ZodError) {
55+
return NextResponse.json(
56+
{ error: error.errors[0]?.message ?? 'Invalid request' },
57+
{ status: 400 }
58+
)
59+
}
5460
const errorMessage =
5561
error instanceof Error ? error.message : 'Failed to list Athena query executions'
5662
logger.error('ListQueryExecutions failed', { error: errorMessage })

apps/sim/app/api/tools/athena/start-query/route.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ export async function POST(request: NextRequest) {
6767
},
6868
})
6969
} catch (error) {
70+
if (error instanceof z.ZodError) {
71+
return NextResponse.json(
72+
{ error: error.errors[0]?.message ?? 'Invalid request' },
73+
{ status: 400 }
74+
)
75+
}
7076
const errorMessage = error instanceof Error ? error.message : 'Failed to start Athena query'
7177
logger.error('StartQuery failed', { error: errorMessage })
7278
return NextResponse.json({ error: errorMessage }, { status: 500 })

apps/sim/app/api/tools/athena/stop-query/route.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ export async function POST(request: NextRequest) {
4343
},
4444
})
4545
} catch (error) {
46+
if (error instanceof z.ZodError) {
47+
return NextResponse.json(
48+
{ error: error.errors[0]?.message ?? 'Invalid request' },
49+
{ status: 400 }
50+
)
51+
}
4652
const errorMessage = error instanceof Error ? error.message : 'Failed to stop Athena query'
4753
logger.error('StopQuery failed', { error: errorMessage })
4854
return NextResponse.json({ error: errorMessage }, { status: 500 })

apps/sim/app/api/tools/cloudformation/describe-stack-drift-detection-status/route.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ export async function POST(request: NextRequest) {
5353
},
5454
})
5555
} catch (error) {
56+
if (error instanceof z.ZodError) {
57+
return NextResponse.json(
58+
{ error: error.errors[0]?.message ?? 'Invalid request' },
59+
{ status: 400 }
60+
)
61+
}
5662
const errorMessage =
5763
error instanceof Error ? error.message : 'Failed to describe stack drift detection status'
5864
logger.error('DescribeStackDriftDetectionStatus failed', { error: errorMessage })

apps/sim/app/api/tools/cloudformation/describe-stack-events/route.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ export async function POST(request: NextRequest) {
7070
output: { events },
7171
})
7272
} catch (error) {
73+
if (error instanceof z.ZodError) {
74+
return NextResponse.json(
75+
{ error: error.errors[0]?.message ?? 'Invalid request' },
76+
{ status: 400 }
77+
)
78+
}
7379
const errorMessage =
7480
error instanceof Error ? error.message : 'Failed to describe CloudFormation stack events'
7581
logger.error('DescribeStackEvents failed', { error: errorMessage })

0 commit comments

Comments
 (0)