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

@ -156,6 +156,13 @@ async def test_write_rows(ds_write, return_rows):
400,
["Too many rows, maximum allowed is 100"],
),
(
"/data/docs/-/insert",
{"rows": [{"id": 1, "title": "Test"}]},
"duplicate_id",
400,
["UNIQUE constraint failed: docs.id"],
),
(
"/data/docs/-/insert",
{"rows": [{"title": "Test"}], "ignore": True, "replace": True},
@ -194,6 +201,10 @@ async def test_write_row_errors(
ds_write, path, input, special_case, expected_status, expected_errors
):
token = write_token(ds_write)
if special_case == "duplicate_id":
await ds_write.get_database("data").execute_write(
"insert into docs (id) values (1)"
)
if special_case == "bad_token":
token += "bad"
kwargs = dict(