Compare commits
2 Commits
74c46f2647
...
04a87c1da6
Author | SHA1 | Date | |
---|---|---|---|
04a87c1da6 | |||
7770a3844c |
@ -4,6 +4,13 @@ from pydantic import ValidationError
|
|||||||
from core.lib import schemas
|
from core.lib import schemas
|
||||||
from core.util import logs
|
from core.util import logs
|
||||||
|
|
||||||
|
# Return error if the schema for the message type is not found
|
||||||
|
STRICT_VALIDATION = False
|
||||||
|
|
||||||
|
# Raise exception if the conversion schema is not found
|
||||||
|
STRICT_CONVERSTION = False
|
||||||
|
|
||||||
|
# TODO: Set them to True when all message types are implemented
|
||||||
|
|
||||||
class BaseExchange(object):
|
class BaseExchange(object):
|
||||||
def __init__(self, account):
|
def __init__(self, account):
|
||||||
@ -34,7 +41,8 @@ class BaseExchange(object):
|
|||||||
else:
|
else:
|
||||||
# Let us know so we can implement it, but don't do anything with it
|
# Let us know so we can implement it, but don't do anything with it
|
||||||
self.log.error(f"No schema for message: {msg_type} - {response}")
|
self.log.error(f"No schema for message: {msg_type} - {response}")
|
||||||
# raise Exception(f"No schema for {msg_type} in schema mapping")
|
if STRICT_CONVERSION:
|
||||||
|
raise Exception(f"No schema for {msg_type} in schema mapping")
|
||||||
return response
|
return response
|
||||||
|
|
||||||
# Use glom to convert the response to the schema
|
# Use glom to convert the response to the schema
|
||||||
@ -52,7 +60,8 @@ class BaseExchange(object):
|
|||||||
if method not in self.schema:
|
if method not in self.schema:
|
||||||
self.log.error(f"Method cannot be validated: {method}")
|
self.log.error(f"Method cannot be validated: {method}")
|
||||||
self.log.debug(f"Response: {response}")
|
self.log.debug(f"Response: {response}")
|
||||||
# return (False, f"Method cannot be validated: {method}")
|
if STRICT_VALIDATION:
|
||||||
|
return (False, f"Method cannot be validated: {method}")
|
||||||
return (True, response)
|
return (True, response)
|
||||||
# Return a dict of the validated response
|
# Return a dict of the validated response
|
||||||
response_valid = self.schema[method](**response).dict()
|
response_valid = self.schema[method](**response).dict()
|
||||||
|
Loading…
Reference in New Issue
Block a user