Query

Module to handle the query submission to the backend.

ERROR_MESSAGES: dict[int, str] = {HTTPStatus.BAD_REQUEST: "Bad request: The server couldn't understand the request. {detailed_message}", HTTPStatus.UNAUTHORIZED: 'Authentication failed: Please check your credentials. {detailed_message}', HTTPStatus.PAYMENT_REQUIRED: "Quota exceeded: You've reached your usage limit. Please upgrade your plan or try again later. {detailed_message}", HTTPStatus.FORBIDDEN: "Access forbidden: You don't have permission to access this resource. {detailed_message}", HTTPStatus.NOT_FOUND: "Resource not found: The requested endpoint doesn't exist. {detailed_message}", HTTPStatus.METHOD_NOT_ALLOWED: 'Method not allowed: The request method is not supported for the requested resource. {detailed_message}', HTTPStatus.PROXY_AUTHENTICATION_REQUIRED: 'Proxy authentication required: The request requires authentication with the proxy. {detailed_message}', HTTPStatus.REQUEST_TIMEOUT: 'Request timeout: The server timed out waiting for the request. {detailed_message}', HTTPStatus.CONFLICT: 'Conflict: The request conflicts with the current state of the server. {detailed_message}', HTTPStatus.GONE: 'Gone: The requested resource is no longer available. {detailed_message}', HTTPStatus.PRECONDITION_FAILED: 'Precondition failed: The server does not meet one of the preconditions in the request. {detailed_message}', HTTPStatus.REQUEST_ENTITY_TOO_LARGE: 'Request entity too large: The request is larger than the server is willing to process. {detailed_message}', HTTPStatus.REQUEST_URI_TOO_LONG: 'Request URI too long: The URI provided was too long for the server to process. {detailed_message}', HTTPStatus.UNSUPPORTED_MEDIA_TYPE: 'Unsupported media type: The request content type is not supported. {detailed_message}', HTTPStatus.REQUESTED_RANGE_NOT_SATISFIABLE: 'Requested range not satisfiable: The requested range is not available. {detailed_message}', HTTPStatus.EXPECTATION_FAILED: 'Expectation failed: The server cannot meet the requirements of the Expect request-header field. {detailed_message}', HTTPStatus.UNPROCESSABLE_ENTITY: 'Unprocessable entity: The request was well-formed but semantically incorrect. {detailed_message}', HTTPStatus.LOCKED: 'Locked: The resource is locked. {detailed_message}', HTTPStatus.FAILED_DEPENDENCY: 'Failed dependency: The request failed due to failure of a previous request. {detailed_message}', HTTPStatus.UPGRADE_REQUIRED: 'Upgrade required: The client should switch to a different protocol. {detailed_message}', HTTPStatus.PRECONDITION_REQUIRED: 'Precondition required: The server requires the request to be conditional. {detailed_message}', HTTPStatus.TOO_MANY_REQUESTS: 'Too many requests: Rate limit exceeded. Please try again later. {detailed_message}', HTTPStatus.REQUEST_HEADER_FIELDS_TOO_LARGE: 'Request header fields too large: The header fields exceed the maximum size. {detailed_message}', HTTPStatus.UNAVAILABLE_FOR_LEGAL_REASONS: 'Unavailable for legal reasons: The requested resource is unavailable due to legal reasons. {detailed_message}', HTTPStatus.INTERNAL_SERVER_ERROR: 'Server error: The backend service encountered an internal error. Please try again later. {detailed_message}', HTTPStatus.NOT_IMPLEMENTED: 'Not implemented: The server does not support the functionality required to fulfill the request. {detailed_message}', HTTPStatus.BAD_GATEWAY: 'Bad gateway: The backend server received an invalid response. Please try again later. {detailed_message}', HTTPStatus.SERVICE_UNAVAILABLE: 'Service unavailable: The backend service is temporarily unavailable. Please try again later. {detailed_message}', HTTPStatus.GATEWAY_TIMEOUT: 'Gateway timeout: The backend service took too long to respond. Please try again later. {detailed_message}', HTTPStatus.HTTP_VERSION_NOT_SUPPORTED: 'HTTP version not supported: The server does not support the HTTP protocol version used in the request. {detailed_message}', HTTPStatus.VARIANT_ALSO_NEGOTIATES: 'Variant also negotiates: The server has an internal configuration error. {detailed_message}', HTTPStatus.INSUFFICIENT_STORAGE: 'Insufficient storage: The server has insufficient storage to complete the request. {detailed_message}', HTTPStatus.LOOP_DETECTED: 'Loop detected: The server detected an infinite loop while processing the request. {detailed_message}', HTTPStatus.NOT_EXTENDED: 'Not extended: Further extensions to the request are required for the server to fulfill it. {detailed_message}', HTTPStatus.NETWORK_AUTHENTICATION_REQUIRED: 'Network authentication required: The client needs to authenticate to gain network access. {detailed_message}'}

Map status codes to error messages

_extract_response_text(response)[source]

Extract text from successful response.

Return type:

str

Parameters:

response – Response object with JSON data

Returns:

Extracted text from response

_handle_error_response(response)[source]

Check response for errors and raise appropriate exceptions.

Return type:

None

Parameters:

response – Response object to check

Raises:

RequestFailedError – If response status code indicates an error

_send_request(endpoint, payload, config)[source]

Send POST request to the backend.

Return type:

Response

Parameters:
  • endpoint – Full URL endpoint

  • payload – Request payload

  • config – Configuration with auth settings

Returns:

Response object

submit(payload, config)[source]

Submit a query to the backend API.

Return type:

str

Parameters:
  • payload – JSON-serializable dictionary containing the query parameters

  • config – Configuration object with backend endpoint information

Raises:

RequestFailedError – If the request fails due to network issues, authentication problems, or server errors

Returns:

The response text from the backend

Return type:

str