Response Structure
All WispHub API endpoints return a standardizedBackendResponse structure. This consistent format simplifies client-side handling and provides rich context about the operation result.
BackendResponse Schema
Every API response follows this generic structure defined inapp/schemas/responses/backend_response.py:8:
Fields
Indicates whether the request was successful.
true for success/info responses, false for errors.The type of response. See Response Types below.
A domain-specific action code that provides context about what happened. See Response Actions below.
The response payload. Type varies by endpoint. Can be
null for error responses or operations without return data.Optional human-readable message providing additional context, especially useful for errors or validation failures.
Optional metadata object containing additional information about the response (e.g., pagination, timestamps).
Response Types
Defined inapp/schemas/responses/response_types.py:3, the type field uses one of three values:
The operation completed successfully.
ok will be true.The operation failed due to an error.
ok will be false and message typically contains details.The operation completed but requires attention (e.g., “not found”, “limit reached”).
ok will be true.The
info type is used for non-error situations that need special handling, such as when a zone has reached its ticket limit or when a search returns no results.Response Actions
Theaction field provides domain-specific context using enum values from app/schemas/responses/response_actions.py. Actions are organized by resource domain:
Client Actions
Ticket Actions
Network Actions
Plan Actions
General Actions
The
ResponseAction type is a union of all action enums, allowing any domain-specific action to be used in the response.Helper Methods
TheBackendResponse class provides three factory methods for creating responses:
Success Response
Defined atapp/schemas/responses/backend_response.py:17:
Error Response
Defined atapp/schemas/responses/backend_response.py:21:
Info Response
Defined atapp/schemas/responses/backend_response.py:25:
Error Handling
The API implements global exception handlers inapp/api/exception_handlers.py to ensure all errors return the standardized BackendResponse format.
Validation Errors (422)
Handler defined atapp/api/exception_handlers.py:8:
HTTP Exceptions (404, etc.)
Handler defined atapp/api/exception_handlers.py:27:
Internal Server Errors (500)
Handler defined atapp/api/exception_handlers.py:42:
HTTP Status Codes
The API uses standard HTTP status codes alongside theBackendResponse structure:
| Status Code | Meaning | Usage |
|---|---|---|
| 200 | OK | Successful request with data returned |
| 422 | Unprocessable Entity | Request validation failed (Pydantic errors) |
| 404 | Not Found | Endpoint not found or resource doesn’t exist |
| 500 | Internal Server Error | Uncaught server-side exception |
Even when an HTTP error status is returned, the response body will always be a valid
BackendResponse object with ok: false and descriptive message.Example Responses
Successful Client Lookup
Client Not Found
Ticket Creation Success
Zone Ticket Limit Reached (Info)
Validation Error
Best Practices
Always check the 'ok' field
Always check the 'ok' field
Use the
ok boolean to determine success/failure before processing data. Even info type responses have ok: true.Use action codes for flow control
Use action codes for flow control
The
action field provides semantic meaning beyond HTTP status codes. Use it to implement domain-specific logic (e.g., redirecting users when ZONE_LIMIT_REACHED).Handle info type responses
Handle info type responses
Don’t treat
type: "info" as errors. These are successful responses that need special UX handling (e.g., showing a warning instead of error).Display message to users
Display message to users
The
message field contains human-readable Spanish text suitable for display in user interfaces.