async def parse_responses(responses): result = (False, "") for r in responses: try: if not result[0]: if isinstance(r, BaseException): result = (False, str(r)) elif r.status == 400: error = await r.text() try: result = (False, errors.DuniterError( bma.parse_error(error)).message) except jsonschema.ValidationError: result = (False, error) elif r.status == 200: result = (True, (await r.json())) elif not result[0]: result = (False, (await r.text())) else: await r.release() except Exception as e: if not result[0]: result = (False, str(e)) return result
def test_parse_error(self): api = API(None, "any") error = parse_error("""{ "ucode": 1005, "message": "Document has unkown fields or wrong line ending format" }""") self.assertEqual(error["ucode"], 1005) self.assertEqual( error["message"], "Document has unkown fields or wrong line ending format")
async def parse_responses(responses): result = (False, "") for r in responses: try: if not result[0]: if isinstance(r, BaseException): result = (False, str(r)) elif r.status == 400: error = await r.text() try: result = (False, errors.DuniterError(bma.parse_error(error)).message) except jsonschema.ValidationError: result = (False, error) elif r.status == 200: result = (True, (await r.json())) elif not result[0]: result = (False, (await r.text())) else: await r.release() except Exception as e: if not result[0]: result = (False, str(e)) return result