Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
docs(search): declare the plugin provider's 502 and 503 answers
Yudhi Armyndharis77917ae01e23
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 5a7334001..742da98f1 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0### Changed+- `GET /search` declares the plugin provider's failure answers in the contract: `502` for an invalid result+ shape and `503` when the provider does not answer; the built-in provider never returns either.- `POST /sessions/{sessionId}/pairing-code`: the 409 description in the OpenAPI contract and API referencenow says to wait for `qr_ready`, not `ready`, which on this route means the session is already linked, andto wait for `ready` once a code was accepted.diff --git a/docs/06-api-specification.md b/docs/06-api-specification.mdindex a6b1d9dcb..535ab83b2 100644--- a/docs/06-api-specification.md+++ b/docs/06-api-specification.md@@ -94,20 +94,20 @@ Validation failures (`statusCode: 400`) return `message` as an **array** of fiel### General Error Codes-| HTTP Status | Meaning | When |-| ----------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |-| `400` | Bad Request | DTO validation failed, unknown body field, or a business precondition not met (e.g. session not active, media over cap) |-| `401` | Unauthorized | Missing/invalid/expired/revoked `X-API-Key` (or `METRICS_TOKEN` for metrics), a blocked source IP, or a key used outside its `allowedSessions` scope |-| `403` | Forbidden | A valid, in-scope key whose **role** is below the route's `@RequireRole` requirement |-| `404` | Not Found | The addressed resource (session, message, webhook, batch, …) does not exist |-| `409` | Conflict | A uniqueness constraint was violated (e.g. duplicate name), or a credential teardown for the same session name is still in flight on `start`/`delete` (retryable; body carries `code: 'SESSION_NAME_TEARDOWN_PENDING'`) |-| `413` | Payload Too Large | Base64 media exceeds the media byte cap (see §6.3) |-| `415` | Unsupported Media | The request has a body carrying a `Content-Encoding` other than `identity`; compressed request bodies are not accepted, as the aggregate body cap counts wire bytes |-| `429` | Too Many Requests | A rate limit was exceeded: the per-client-IP tiers, the ingress per-instance limit, or send pacing (body carries `code: 'SEND_PACING_LIMITED'` and `retryAfterSeconds`); honor `Retry-After` when present |-| `500` | Internal Server Error | Send failed at the WhatsApp engine or an unexpected server error |-| `501` | Not Implemented | The operation is not supported by the active engine (see the capability matrix, docs/29) |-| `502` | Bad Gateway | An engine transport failure (e.g. a dead Baileys socket); retryable |-| `503` | Service Unavailable | A dependency or the session is not ready (boot draining, a datastore down, the engine reconnecting); retryable |+| HTTP Status | Meaning | When |+| ----------- | --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |+| `400` | Bad Request | DTO validation failed, unknown body field, or a business precondition not met (e.g. session not active, media over cap) |+| `401` | Unauthorized | Missing/invalid/expired/revoked `X-API-Key` (or `METRICS_TOKEN` for metrics), a blocked source IP, or a key used outside its `allowedSessions` scope |+| `403` | Forbidden | A valid, in-scope key whose **role** is below the route's `@RequireRole` requirement |+| `404` | Not Found | The addressed resource (session, message, webhook, batch, …) does not exist |+| `409` | Conflict | A uniqueness constraint was violated (e.g. duplicate name); a credential teardown for the same session name is still in flight on `start`/`delete` (retryable; body carries `code: 'SESSION_NAME_TEARDOWN_PENDING'`); or, on routes that reach a WhatsApp engine, the engine exists but is not ready yet (retryable; each route section carries the exact wording); or, on a multi-node deployment, another node currently owns the session's live engine (retryable) |+| `413` | Payload Too Large | Base64 media exceeds the media byte cap (see §6.3) |+| `415` | Unsupported Media | The request has a body carrying a `Content-Encoding` other than `identity`; compressed request bodies are not accepted, as the aggregate body cap counts wire bytes |+| `429` | Too Many Requests | A rate limit was exceeded: the per-client-IP tiers, the ingress per-instance limit, or send pacing (body carries `code: 'SEND_PACING_LIMITED'` and `retryAfterSeconds`); honor `Retry-After` when present |+| `500` | Internal Server Error | Send failed at the WhatsApp engine or an unexpected server error |+| `501` | Not Implemented | The operation is not supported by the active engine (see the capability matrix, docs/29) |+| `502` | Bad Gateway | An engine transport failure (e.g. a dead Baileys socket; retryable), or an upstream component returned something unusable (not retryable; each route section carries the exact wording) |+| `503` | Service Unavailable | A dependency or the session is not ready (boot draining, a datastore down, the engine reconnecting); retryable |### Timestamp Conventions@@ -2521,7 +2521,7 @@ Raw array (no envelope). The service calls `engine.getGroups()`, projects each e]```-**Errors:** `400` session is not started · `401` missing/invalid `X-API-Key` · `409` conflict or engine not ready (retryable) · `503` session not ready or dependency unavailable (retryable)+**Errors:** `400` session is not started · `401` missing/invalid `X-API-Key` · `404` session not found · `409` conflict or engine not ready (retryable) · `503` session not ready or dependency unavailable (retryable)#### GET /api/sessions/:sessionId/groups/:groupId@@ -6125,8 +6125,9 @@ Search messages across sessions (active search provider).SQLite FTS5 query (unbalanced quote/paren, bare operator) — Postgres's `websearch_to_tsquery` istolerant and has no equivalent · `401` missing/invalid `X-API-Key` · `403` key role below `OPERATOR` ·`501` no search provider configured (including a non-FTS5 SQLite build, where the provider is absent) ·-`503` active provider unhealthy (**reserved**: the built-in provider does not return it; it is the-contract surface for a future plugin provider whose `search()` throws `ServiceUnavailableException`).+`502` the active plugin provider returned an invalid result shape (not retryable until the plugin is fixed) ·+`503` the active plugin provider did not answer (worker not running, timed out, or reported a failure;+retryable). The built-in provider returns neither `502` nor `503`.> Scoping is authoritative: a scoped API key's `allowedSessions` is applied server-side and cannot be> overridden via the query — there is no `sessionIds` query parameter, and `SearchService` overwritesdiff --git a/openapi.json b/openapi.jsonindex f879001bb..801872601 100644--- a/openapi.json+++ b/openapi.json@@ -9410,6 +9410,12 @@},"501": {"description": "No search provider configured"+ },+ "502": {+ "description": "The active plugin search provider returned a result shape that failed validation, so nothing trustworthy could be forwarded. The built-in provider never returns this."+ },+ "503": {+ "description": "The active plugin search provider did not answer: its worker is not running, timed out, or reported a failure. The built-in provider never returns this. Retryable."}},"summary": "Search messages across sessions (active search provider)",diff --git a/src/modules/search/search.controller.ts b/src/modules/search/search.controller.tsindex 9a254c176..a89480517 100644--- a/src/modules/search/search.controller.ts+++ b/src/modules/search/search.controller.ts@@ -18,6 +18,18 @@ export class SearchController {@ApiResponse({ status: 200, description: 'Search results from the active provider', type: SearchResultsResponseDto })@ApiResponse({ status: 400, description: 'Empty or whitespace-only "q"' })@ApiResponse({ status: 501, description: 'No search provider configured' })+ @ApiResponse({+ status: 502,+ description:+ 'The active plugin search provider returned a result shape that failed validation, so nothing ' ++ 'trustworthy could be forwarded. The built-in provider never returns this.',+ })+ @ApiResponse({+ status: 503,+ description:+ 'The active plugin search provider did not answer: its worker is not running, timed out, or reported ' ++ 'a failure. The built-in provider never returns this. Retryable.',+ })@ApiQuery({ name: 'q', required: true, description: 'Search term (required, non-empty)' })@ApiQuery({ name: 'sessionId', required: false, description: 'Restrict to a single session' })@ApiQuery({ name: 'chatId', required: false, description: 'Restrict to a single chat id' })