def test_raise_error(self): other = lambda v: DataError('other error', code='other_error') fail_other = t.Atom('a') & other res = extract_error(fail_other, 'a') assert res == 'other error' ttt = t.And(other, t.Any) res = extract_error(ttt, 45) assert res == 'other error'
async def check(self, value: Any): """ Check if value is valid by template Raises: ValueError if template is not set trafaret.DataError if value is not valid """ if self._template is None: raise ValueError("Template not set") errors = [] for template in self._template: try: await template.async_check(value) except DataError as e: errors.append(e.error) else: return raise DataError(error='\n'.join(errors))
def test_raise_error(self): other = lambda v: DataError('other error') fail_other = t.Atom('a') & other res = extract_error(fail_other, 'a') self.assertEqual(res, 'other error')
def _data_error_response(e: DataError): return {"message": "Bad request", "errors": e.as_dict()}, 400