Remove try catch from rows. Correct status codes.

This commit is contained in:
Mel O'Hagan 2022-10-27 13:49:19 +01:00
parent 5261438932
commit 5aa98fcbac
1 changed files with 44 additions and 81 deletions

View File

@ -30,7 +30,6 @@ export async function patch(ctx: any): Promise<any> {
if (body && !body._id) { if (body && !body._id) {
return save(ctx) return save(ctx)
} }
try {
const { row, table } = await quotas.addQuery( const { row, table } = await quotas.addQuery(
() => pickApi(tableId).patch(ctx), () => pickApi(tableId).patch(ctx),
{ {
@ -42,9 +41,6 @@ export async function patch(ctx: any): Promise<any> {
ctx.eventEmitter.emitRow(`row:update`, appId, row, table) ctx.eventEmitter.emitRow(`row:update`, appId, row, table)
ctx.message = `${table.name} updated successfully.` ctx.message = `${table.name} updated successfully.`
ctx.body = row ctx.body = row
} catch (err) {
ctx.throw(400, err)
}
} }
export const save = async (ctx: any) => { export const save = async (ctx: any) => {
@ -55,7 +51,6 @@ export const save = async (ctx: any) => {
if (body && body._id) { if (body && body._id) {
return patch(ctx) return patch(ctx)
} }
try {
const { row, table } = await quotas.addRow(() => const { row, table } = await quotas.addRow(() =>
quotas.addQuery(() => pickApi(tableId).save(ctx), { quotas.addQuery(() => pickApi(tableId).save(ctx), {
datasourceId: tableId, datasourceId: tableId,
@ -65,42 +60,26 @@ export const save = async (ctx: any) => {
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:save`, appId, row, table) ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:save`, appId, row, table)
ctx.message = `${table.name} saved successfully` ctx.message = `${table.name} saved successfully`
ctx.body = row ctx.body = row
} catch (err) {
ctx.throw(400, err)
}
} }
export async function fetchView(ctx: any) { export async function fetchView(ctx: any) {
const tableId = getTableId(ctx) const tableId = getTableId(ctx)
try {
ctx.body = await quotas.addQuery(() => pickApi(tableId).fetchView(ctx), { ctx.body = await quotas.addQuery(() => pickApi(tableId).fetchView(ctx), {
datasourceId: tableId, datasourceId: tableId,
}) })
} catch (err) {
ctx.throw(400, err)
}
} }
export async function fetch(ctx: any) { export async function fetch(ctx: any) {
const tableId = getTableId(ctx) const tableId = getTableId(ctx)
try {
ctx.body = await quotas.addQuery(() => pickApi(tableId).fetch(ctx), { ctx.body = await quotas.addQuery(() => pickApi(tableId).fetch(ctx), {
datasourceId: tableId, datasourceId: tableId,
}) })
} catch (err) {
ctx.throw(400, err)
}
} }
export async function find(ctx: any) { export async function find(ctx: any) {
const tableId = getTableId(ctx) const tableId = getTableId(ctx)
try {
ctx.body = await quotas.addQuery(() => pickApi(tableId).find(ctx), { ctx.body = await quotas.addQuery(() => pickApi(tableId).find(ctx), {
datasourceId: tableId, datasourceId: tableId,
}) })
} catch (err) {
ctx.throw(400, err)
}
} }
export async function destroy(ctx: any) { export async function destroy(ctx: any) {
@ -137,46 +116,30 @@ export async function destroy(ctx: any) {
export async function search(ctx: any) { export async function search(ctx: any) {
const tableId = getTableId(ctx) const tableId = getTableId(ctx)
try {
ctx.status = 200 ctx.status = 200
ctx.body = await quotas.addQuery(() => pickApi(tableId).search(ctx), { ctx.body = await quotas.addQuery(() => pickApi(tableId).search(ctx), {
datasourceId: tableId, datasourceId: tableId,
}) })
} catch (err) {
ctx.throw(400, err)
}
} }
export async function validate(ctx: any) { export async function validate(ctx: any) {
const tableId = getTableId(ctx) const tableId = getTableId(ctx)
try {
ctx.body = await pickApi(tableId).validate(ctx) ctx.body = await pickApi(tableId).validate(ctx)
} catch (err) {
ctx.throw(400, err)
}
} }
export async function fetchEnrichedRow(ctx: any) { export async function fetchEnrichedRow(ctx: any) {
const tableId = getTableId(ctx) const tableId = getTableId(ctx)
try {
ctx.body = await quotas.addQuery( ctx.body = await quotas.addQuery(
() => pickApi(tableId).fetchEnrichedRow(ctx), () => pickApi(tableId).fetchEnrichedRow(ctx),
{ {
datasourceId: tableId, datasourceId: tableId,
} }
) )
} catch (err) {
ctx.throw(400, err)
}
} }
export const exportRows = async (ctx: any) => { export const exportRows = async (ctx: any) => {
const tableId = getTableId(ctx) const tableId = getTableId(ctx)
try {
ctx.body = await quotas.addQuery(() => pickApi(tableId).exportRows(ctx), { ctx.body = await quotas.addQuery(() => pickApi(tableId).exportRows(ctx), {
datasourceId: tableId, datasourceId: tableId,
}) })
} catch (err) {
ctx.throw(400, err)
}
} }