Skip to content

Commit 37f7db0

Browse files
fix(tables): return 404 when patching a missing view
1 parent 20150f7 commit 37f7db0

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

apps/sim/app/api/table/[tableId]/views/[viewId]/route.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ export const PATCH = withRouteHandler(
5151
isDefault,
5252
columns,
5353
})
54+
if (!view) {
55+
return NextResponse.json({ error: 'View not found' }, { status: 404 })
56+
}
5457

5558
return NextResponse.json({ success: true, data: { view } })
5659
} catch (error) {

apps/sim/lib/table/views/service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export interface UpdateTableViewData {
161161
* overlapping partial writes — a column resize landing while a pin is in flight —
162162
* can't each replace the whole blob from their own stale snapshot.
163163
*/
164-
export async function updateTableView(data: UpdateTableViewData): Promise<TableView> {
164+
export async function updateTableView(data: UpdateTableViewData): Promise<TableView | null> {
165165
const patch: Partial<typeof tableViews.$inferInsert> = { updatedAt: new Date() }
166166
if (data.name !== undefined) patch.name = normalizeName(data.name)
167167
if (data.config !== undefined) patch.config = data.config
@@ -193,7 +193,9 @@ export async function updateTableView(data: UpdateTableViewData): Promise<TableV
193193
return updated
194194
})
195195

196-
if (!row) throw new TableViewValidationError('View not found')
196+
// `null`, not a validation error: an absent view is a missing resource, and the
197+
// route maps it to 404 the same way `deleteTableView`'s `false` does.
198+
if (!row) return null
197199

198200
return toTableView(row, data.columns)
199201
}

0 commit comments

Comments
 (0)