Check for empty payload (#2903)

This commit is contained in:
Pere Miquel Brull 2022-02-21 23:19:27 +01:00 committed by GitHub
parent 1e556d2ac1
commit 1656ca460c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -83,6 +83,13 @@ class InvalidEntityException(Exception):
""" """
class EmptyPayloadException(Exception):
"""
Raise when receiving no data, even if no exception
during the API call is received
"""
class EntityList(Generic[T], BaseModel): class EntityList(Generic[T], BaseModel):
""" """
Pydantic Entity list model Pydantic Entity list model
@ -363,6 +370,10 @@ class OpenMetadata(
) )
resp = self.client.put(self.get_suffix(entity), data=data.json()) resp = self.client.put(self.get_suffix(entity), data=data.json())
if not resp:
raise EmptyPayloadException(
f"Got an empty response when trying to PUT to {self.get_suffix(entity)}, {data.json()}"
)
return entity_class(**resp) return entity_class(**resp)
def get_by_name( def get_by_name(
@ -398,6 +409,10 @@ class OpenMetadata(
fields_str = "?fields=" + ",".join(fields) if fields else "" fields_str = "?fields=" + ",".join(fields) if fields else ""
try: try:
resp = self.client.get(f"{self.get_suffix(entity)}/{path}{fields_str}") resp = self.client.get(f"{self.get_suffix(entity)}/{path}{fields_str}")
if not resp:
raise EmptyPayloadException(
f"Got an empty response when trying to GET from {self.get_suffix(entity)}/{path}{fields_str}"
)
return entity(**resp) return entity(**resp)
except APIError as err: except APIError as err:
logger.error( logger.error(