diff --git a/packages/server/src/api/controllers/view/viewsV2.ts b/packages/server/src/api/controllers/view/viewsV2.ts index 5376ce49c3..ff8daf3bc6 100644 --- a/packages/server/src/api/controllers/view/viewsV2.ts +++ b/packages/server/src/api/controllers/view/viewsV2.ts @@ -123,9 +123,11 @@ async function parseSchema(view: CreateViewRequest) { } export async function get(ctx: Ctx) { - ctx.body = { - data: await sdk.views.getEnriched(ctx.params.viewId), + const view = await sdk.views.getEnriched(ctx.params.viewId) + if (!view) { + ctx.throw(404) } + ctx.body = { data: view } } export async function fetch(ctx: Ctx) { diff --git a/packages/server/src/sdk/app/views/index.ts b/packages/server/src/sdk/app/views/index.ts index 4f978253d6..157e741acd 100644 --- a/packages/server/src/sdk/app/views/index.ts +++ b/packages/server/src/sdk/app/views/index.ts @@ -40,7 +40,9 @@ export async function get(viewId: string): Promise { return pickApi(tableId).get(viewId) } -export async function getEnriched(viewId: string): Promise { +export async function getEnriched( + viewId: string +): Promise { const { tableId } = utils.extractViewInfoFromID(viewId) return pickApi(tableId).getEnriched(viewId) } diff --git a/packages/server/src/sdk/app/views/internal.ts b/packages/server/src/sdk/app/views/internal.ts index 4f7abad357..9eeebc4cc4 100644 --- a/packages/server/src/sdk/app/views/internal.ts +++ b/packages/server/src/sdk/app/views/internal.ts @@ -17,13 +17,15 @@ export async function get(viewId: string): Promise { return ensureQueryUISet(found) } -export async function getEnriched(viewId: string): Promise { +export async function getEnriched( + viewId: string +): Promise { const { tableId } = utils.extractViewInfoFromID(viewId) const table = await sdk.tables.getTable(tableId) const views = Object.values(table.views!).filter(isV2) const found = views.find(v => v.id === viewId) if (!found) { - throw new Error("No view found") + return } return await enrichSchema(ensureQueryUISet(found), table.schema) }