Commit 470bcc33 authored by BODERE's avatar BODERE
Browse files

fix: add logging

parent 3eb6c702
Pipeline #6491 passed with stage
in 45 seconds
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Opensearch engines"""
import logging
from typing import Dict, List, Optional, Tuple
from urllib.parse import parse_qs, quote, urlencode, urlsplit, urlunsplit
from xml.etree import ElementTree as Element
......@@ -23,14 +23,15 @@ class OpensearchEngine:
def __init__(self, root_path: str, timeout: float = 10.0):
self.root_path = root_path
self.timeout = timeout
self._log = logging.getLogger()
async def request(self, params: OpensearchQueryParameters) -> Optional[OpensearchResponse]:
async def request_hook(request):
print(f"Request event hook: {request.method} {request.url} - Waiting for response")
self._log.debug("Request event hook: %s %s - Waiting for response", request.method, request.url)
async def response_hook(response):
request = response.request
print(f"Response event hook: {request.method} {request.url} - Status {response.status_code}")
self._log.debug(f"Response event hook: - Status %d", request.method, request.url, response.status_code)
url = self._build_search_url(params)
opensearch_response = OpensearchResponse(query=OpensearchQuery(params=params, url=url))
......@@ -43,7 +44,8 @@ class OpensearchEngine:
opensearch_response.header, opensearch_response.entries = self._process_response(raw_response)
except httpx.ReadTimeout:
opensearch_response.errors.append("Timeout occurred")
except ValidationError:
except ValidationError as e:
opensearch_response.errors.append("Not a valid response")
except Exception as e:
msg = str(e).strip()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment