Handle database errors in /-/insert, refs #1866, #1873

Also improved API explorer to show HTTP status of response, refs #1871
This commit is contained in:
Simon Willison 2022-11-01 12:59:17 -07:00
commit 497290beaf
3 changed files with 24 additions and 6 deletions

View file

@ -1206,7 +1206,10 @@ class TableInsertView(BaseView):
else:
table.insert_all(rows, ignore=ignore, replace=replace)
rows = await db.execute_write_fn(insert_rows)
try:
rows = await db.execute_write_fn(insert_rows)
except Exception as e:
return _error([str(e)])
result = {"ok": True}
if should_return:
result["rows"] = rows