some better error handling

This commit is contained in:
Kay Faraday 2021-12-10 02:56:48 +00:00
parent be4c6cdeb8
commit 6cf9d75c81
1 changed files with 14 additions and 1 deletions

View File

@ -40,7 +40,20 @@ dprint = ContextVar('dprint')
http = ContextVar('http')
async def handler(request):
hconfig = config['hosts'][request.host]
try:
await _handler(request)
except aiohttp.ClientConnectorError:
raise web.HTTPServiceUnavailable(
text=f'{request.host} is temporarily unavailable. Try again later.',
)
async def _handler(request):
try:
hconfig = config['hosts'][request.host]
except KeyError:
# this should only happen if our reverse proxy is set to proxy everything to us
raise web.HTTPNotFound()
dprint.set(dprint_factory())
async with http().request(
request.method,