Skip to content

Commit cab90e7

Browse files
committed
fix(grafana): surface upstream error when the prefetch GET fails
Check response.ok on the existing-resource GET in both update routes and return the upstream status/body, matching how the tool framework surfaced GET errors before the move to internal routes (the framework checks response.ok before transformResponse). Without this, a failed prefetch produced a generic 'Failed to fetch existing ...' message and dropped Grafana's error detail.
1 parent c14e497 commit cab90e7

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

apps/sim/app/api/tools/grafana/update_alert_rule/route.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
7878
headers: getHeaders,
7979
})
8080

81+
if (!getResponse.ok) {
82+
const errorText = await getResponse.text()
83+
return NextResponse.json({
84+
success: false,
85+
output: {},
86+
error: `Failed to fetch existing alert rule: ${errorText}`,
87+
})
88+
}
89+
8190
const existingRule = (await getResponse.json()) as any
8291

8392
if (!existingRule || !existingRule.uid) {

apps/sim/app/api/tools/grafana/update_dashboard/route.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
7777
headers: getHeaders,
7878
})
7979

80+
if (!getResponse.ok) {
81+
const errorText = await getResponse.text()
82+
return NextResponse.json({
83+
success: false,
84+
output: {},
85+
error: `Failed to fetch existing dashboard: ${errorText}`,
86+
})
87+
}
88+
8089
const existing = (await getResponse.json()) as any
8190
const existingDashboard = existing.dashboard
8291
const existingMeta = existing.meta

0 commit comments

Comments
 (0)