Make failing during validation or conversion configurable

This commit is contained in:
Mark Veidemanis 2022-11-02 19:11:32 +00:00
parent 74c46f2647
commit 7770a3844c
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 7 additions and 2 deletions

View File

@ -4,6 +4,9 @@ from pydantic import ValidationError
from core.lib import schemas from core.lib import schemas
from core.util import logs from core.util import logs
STRICT_VALIDATION = False
STRICT_CONVERSTION = False
class BaseExchange(object): class BaseExchange(object):
def __init__(self, account): def __init__(self, account):
@ -34,7 +37,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 +56,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()