Handle errors better
This commit is contained in:
		| @@ -35,7 +35,11 @@ async def new_message(event): | |||||||
|     logging.info('[SEND] {}: {}'.format(name, text)) |     logging.info('[SEND] {}: {}'.format(name, text)) | ||||||
|  |  | ||||||
|     data = dict(name=name, message=text) |     data = dict(name=name, message=text) | ||||||
|  |     try: | ||||||
|         await web.post(api('/up/sendmessage'), json=data) |         await web.post(api('/up/sendmessage'), json=data) | ||||||
|  |     except aiohttp.ClientError: | ||||||
|  |         logging.exception('Problem sending message to dynmap:') | ||||||
|  |  | ||||||
|  |  | ||||||
| async def main(): | async def main(): | ||||||
|     global web |     global web | ||||||
| @@ -45,6 +49,7 @@ async def main(): | |||||||
|     logging.info('Bridge loaded') |     logging.info('Bridge loaded') | ||||||
|  |  | ||||||
|     while True: |     while True: | ||||||
|  |         try: | ||||||
|             async with web.get(api('/up/world/world/' + str(last_time))) as res: |             async with web.get(api('/up/world/world/' + str(last_time))) as res: | ||||||
|                 j = await res.json(content_type='text/plain;charset=utf-8') |                 j = await res.json(content_type='text/plain;charset=utf-8') | ||||||
|                 last_time = j['timestamp'] |                 last_time = j['timestamp'] | ||||||
| @@ -61,6 +66,8 @@ async def main(): | |||||||
|                     logging.info('[RECV] ' + message) |                     logging.info('[RECV] ' + message) | ||||||
|                     await bot.send_message(settings.CHAT_ID, message) |                     await bot.send_message(settings.CHAT_ID, message) | ||||||
|                     last_msg = message |                     last_msg = message | ||||||
|  |         except aiohttp.ClientError: | ||||||
|  |             logging.exception('Problem getting message from dynmap:') | ||||||
|  |  | ||||||
|         await asyncio.sleep(1) |         await asyncio.sleep(1) | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user