some better error handling
This commit is contained in:
parent
be4c6cdeb8
commit
6cf9d75c81
15
replacer.py
15
replacer.py
|
@ -40,7 +40,20 @@ dprint = ContextVar('dprint')
|
||||||
http = ContextVar('http')
|
http = ContextVar('http')
|
||||||
|
|
||||||
async def handler(request):
|
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())
|
dprint.set(dprint_factory())
|
||||||
async with http().request(
|
async with http().request(
|
||||||
request.method,
|
request.method,
|
||||||
|
|
Loading…
Reference in New Issue