kbws.responses module#

Build FDSN-WS standard error responses.

All FDSN error responses share one plain-text template (see the FDSN Web Services Specification). These helpers keep validation, service-availability, and backend failures in a consistent envelope instead of exposing framework error shapes.

Example

>>> from kbws.responses import fdsn_response, BAD_REQUEST
>>> return fdsn_response(request, BAD_REQUEST, detail=str(exc), service_version=VERSION)
class kbws.responses.ResponseCode(code: int, message: str)[source]#

Bases: object

FDSN-WS standard response code and message.

code: int#
message: str#
kbws.responses.fdsn_response(request: Request, response_code: ResponseCode, detail: str, service_version: str) → PlainTextResponse[source]#

Build the standard FDSN plain-text error response for response_code.

Parameters:
  • request (fastapi.Request) – Used to fill in the usage-docs URI and the submitted URL/query.

  • response_code (ResponseCode) – One of the module-level constants, e.g. BAD_REQUEST, NO_DATA_ALT.

  • detail (str) – Specific, request-dependent error detail (e.g. a validation message).

  • service_version (str) – The version of the FDSN service that raised the error.

kbws.responses.service_docs_uri(request: Request) → str[source]#

Return a root-relative documentation URI for the requested FDSN service.

FDSN routes are rooted at /fdsnws/<service>/<major-version>. A root-relative URI avoids depending on the deployment’s public scheme, hostname, port, or proxy headers, while retaining any path under which the service is exposed.