Skip to content

Commit

Permalink
fix: missing indention
Browse files Browse the repository at this point in the history
  • Loading branch information
ghadeer-x committed Mar 4, 2024
1 parent 198ce81 commit 0d8260a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
{{ header_params | join(',\n') | safe }}
{{ header_params | join(',\n') | safe }}
}

query_params : Dict[str,Any] = {
Expand Down Expand Up @@ -49,20 +49,20 @@ with httpx.Client(base_url=base_path, verify=api_config.verify, timeout=api_conf
if inital_response.status != {{ return_type.status_code }}:
response = None
{% if async_client %}
try:
try:
response = await inital_response.json()
except Exception as e:
response = await inital_response.text()
{% else %}
try:
try:
response = inital_response.json()
except Exception as e:
response = inital_response.text
{% endif %}
{% if async_client %}
raise ApiException(status_code=inital_response.status, response=response)
raise HTTPException(status_code=inital_response.status, response=response)
{% else %}
raise ApiException(status_code=inital_response.status_code, response=response)
raise HTTPException(status_code=inital_response.status_code, response=response)
{% endif %}
{% if return_type.type is none or return_type.type.converted_type is none %}
return None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import httpx
from pydantic import BaseModel
from typing import Optional, Any, Union
from httpx import Response

from typing import Any
class UIErrorMessage(BaseModel):
en: str
ar: str
Expand All @@ -25,28 +25,19 @@ class APIConfig(BaseModel):


class HTTPException(Exception):
def __init__(self, response : Optional[Response] = None, error: Optional[Any]=None, async_client:Optional[bool] = False):
def __init__(self, response : Optional[Any] = None, error: Optional[Any]=None, status_code: Optional[int] = None):

try:
if async_client:
self.details = ErrorResponseDetails(**response.json().get("detail"))

if response.json().get("response", None):
self.details.response = response.json().get("response")
else:
self.details = ErrorResponseDetails(**response.get("detail"))
if response.get("response", None):
self.details.response = response.get("response")

except Exception as e:
if hasattr(response, "text"):
self.details = response.text
else:
self.details = response

if response is not None:
if hasattr(response, "status_code"):
self.status_code = response.status_code
elif hasattr(response, "status"):
self.status_code = response.status
self.status_code = status_code

elif hasattr(error, "status_code"):
self.status_code = error.status_code
self.http_code = error.status_code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
{{ header_params | join(',\n') | safe }}
{{ header_params | join(',\n') | safe }}
}
query_params : Dict[str,Any] = {
{% if query_params|length > 0 %}
Expand Down Expand Up @@ -47,6 +47,12 @@ with httpx.Client(base_url=base_path, verify=api_config.verify, timeout=api_conf

if response.status_code != {{ return_type.status_code }}:
raise HTTPException(response=response)
try:
_response = response.json()
except Exception as e:
_response = response.text
raise HTTPException(status_code=_response.status_code, response=_response)


{% if return_type.type is none or return_type.type.converted_type is none %}
return None
Expand Down

0 comments on commit 0d8260a

Please sign in to comment.