Skip to content

Commit 2593478

Browse files
committed
fix: SCHEMA_MISMATCH→400, MEMORY_EXCEEDED→503 HTTP status + document error code mapping
- worker.ts: SCHEMA_MISMATCH now returns 400 (was 500), MEMORY_EXCEEDED returns 503 - docs: add HTTP status code mapping table to error-handling page
1 parent a4c6376 commit 2593478

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

docs/src/content/docs/error-handling.mdx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,31 @@ try {
6161

6262
Already-wrapped `QueryModeError` instances pass through unchanged.
6363

64+
## HTTP status codes
65+
66+
When using the HTTP API (`/query`, `/write`, etc.), error codes map to HTTP status codes:
67+
68+
| Error code | HTTP status | Meaning |
69+
|-----------|-------------|---------|
70+
| `TABLE_NOT_FOUND` | 404 | Table doesn't exist in R2 |
71+
| `COLUMN_NOT_FOUND` | 404 | Column not in schema |
72+
| `INVALID_FILTER` | 400 | Malformed filter op or value |
73+
| `INVALID_FORMAT` | 400 | File can't be parsed |
74+
| `INVALID_AGGREGATE` | 400 | Bad aggregate function |
75+
| `SCHEMA_MISMATCH` | 400 | Column type doesn't match operation |
76+
| `MEMORY_EXCEEDED` | 503 | Operator exceeded memory budget |
77+
| `QUERY_TIMEOUT` | 504 | Total query time exceeded |
78+
| `NETWORK_TIMEOUT` | 504 | R2 or RPC call timed out |
79+
| `QUERY_FAILED` | 500 | Unclassified error |
80+
| *(SyntaxError)* | 400 | Malformed JSON request body |
81+
| *(CAS conflict)* | 409 | Concurrent write conflict |
82+
83+
The response body always includes `{ error: string }` and, for `QueryModeError`, `{ code: string }`:
84+
85+
```json
86+
{ "error": "Column not found in events: foo", "code": "SCHEMA_MISMATCH" }
87+
```
88+
6489
## SQL errors
6590

6691
SQL syntax errors throw `SqlParseError` or `SqlLexerError` (not `QueryModeError`) with a `position` field indicating where the error occurred:

src/worker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,9 @@ export default {
209209
let status = 500;
210210
if (err instanceof QueryModeError) {
211211
if (err.code === "TABLE_NOT_FOUND" || err.code === "COLUMN_NOT_FOUND") status = 404;
212-
else if (err.code === "INVALID_FILTER" || err.code === "INVALID_FORMAT" || err.code === "INVALID_AGGREGATE") status = 400;
212+
else if (err.code === "INVALID_FILTER" || err.code === "INVALID_FORMAT" || err.code === "INVALID_AGGREGATE" || err.code === "SCHEMA_MISMATCH") status = 400;
213213
else if (err.code === "QUERY_TIMEOUT" || err.code === "NETWORK_TIMEOUT") status = 504;
214+
else if (err.code === "MEMORY_EXCEEDED") status = 503;
214215
} else if (msg.includes("CAS failed")) {
215216
status = 409;
216217
} else if (msg.includes("not found")) {

0 commit comments

Comments
 (0)