How to use the serpyco.ValidationError function in serpyco

To help you get started, we’ve selected a few serpyco examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github algoo / hapic / hapic / processor / serpyco.py View on Github external
def load(self, data: typing.Any) -> typing.Any:
        """
        Use schema to validate given data and return dataclass instance.
        If validation fail, raise InputValidationException
        :param data: data to validate and process
        :return: schema dataclass instance
        """
        # Prevent serpyco error when Rrequest context give us a MultiDictProxy
        if isinstance(data, (MultiDictProxy, MultiDict)):
            data = dict(data)

        try:
            return self.serializer.load(data)
        except ValidationError as exc:
            raise ValidationException("Error when loading: {}".format(exc.args[0])) from exc
        except Exception as exc:
            raise ValidationException(
                'Unknown error when serpyco load: "{}": "{}"'.format(type(exc).__name__, str(exc))
            ) from exc

serpyco

Fast serialization of dataclasses using Cython

MIT
Latest version published 8 months ago

Package Health Score

53 / 100
Full package analysis