Skip to content

Commit

Permalink
Merge branch 'feature/51-improve-error-message-when-pydantic-v'
Browse files Browse the repository at this point in the history
  • Loading branch information
leonhard-s committed May 15, 2021
2 parents e19c0d8 + aaa2891 commit 3841386
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion auraxium/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
]

__author__ = 'Leonhard S.'
__version__ = '0.2.0b2'
__version__ = '0.2.0b3'
6 changes: 6 additions & 0 deletions auraxium/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ def __init__(self, data: CensusData, client: RequestClient) -> None:
try:
self.data = self._model(**data)
except pydantic.ValidationError as err:
_log.warning(
'Encountered unsupported payload: %s\n'
'This message means that the Auraxium data model must '
'be updated. Please ensure you are on the latest '
'version of the Auraxium library and report this '
'message to the project maintainers.', data)
raise PayloadError(
f'Unable to instantiate {self.__class__.__name__} instance '
f'from given payload: {err}', data) from err
Expand Down
12 changes: 11 additions & 1 deletion auraxium/event/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import (Any, Callable, Coroutine, Dict, Iterator, List, Optional, Type, TypeVar, Union,
cast, overload)
import backoff
import pydantic

import websockets

Expand Down Expand Up @@ -376,7 +377,16 @@ def _process_payload(self, response: str) -> None:
# Event messages
if service == 'event':
if data['type'] == 'serviceMessage':
event = _event_factory(cast(CensusData, data['payload']))
try:
event = _event_factory(cast(CensusData, data['payload']))
except pydantic.ValidationError:
_log.warning(
'Ignoring unsupported payload: %s\n'
'This message means that the Auraxium data model must '
'be updated. Please ensure you are on the latest '
'version of the Auraxium library and report this '
'message to the project maintainers.', data['payload'])
return
_log.debug('%s event received, dispatching...',
event.event_name)
self.dispatch(event)
Expand Down

0 comments on commit 3841386

Please sign in to comment.