Commit 3eb6c702 authored by BODERE's avatar BODERE
Browse files

fix: error message

parent a18803ad
......@@ -7,6 +7,7 @@ from urllib.parse import parse_qs, quote, urlencode, urlsplit, urlunsplit
from xml.etree import ElementTree as Element
import httpx
from pydantic import ValidationError
from starlette.responses import Response
from opensearx_ws.opensearch.model import (OpensearchQuery,
......@@ -41,13 +42,17 @@ class OpensearchEngine:
raw_response = await client.get(url=url, timeout=self.timeout)
opensearch_response.header, opensearch_response.entries = self._process_response(raw_response)
except httpx.ReadTimeout:
opensearch_response.errors = ["Timeout occurred"]
opensearch_response.errors.append("Timeout occurred")
except ValidationError:
opensearch_response.errors.append("Not a valid response")
except Exception as e:
print(str(e.with_traceback()))
opensearch_response.errors = str(e).split('\n')
msg = str(e).strip()
if not msg:
msg = "Empty response"
opensearch_response.errors.append(msg)
finally:
# if opensearch_response.header is None and not opensearch_response.errors:
# opensearch_response.errors.append("Not a valid response")
if opensearch_response.header is None and not opensearch_response.errors:
opensearch_response.errors.append("Empty response")
return opensearch_response
def _build_search_url(self, params: OpensearchQueryParameters) -> str:
......
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