handle configuration when domain does not exist

This commit is contained in:
Maxime Alves LIRMM@home 2020-11-04 12:31:11 +01:00
parent 4782764059
commit 73d49031a7
1 changed files with 6 additions and 1 deletions

View File

@ -1,6 +1,7 @@
""" """
DomainMiddleware DomainMiddleware
""" """
import configparser
import logging import logging
from starlette.datastructures import URL from starlette.datastructures import URL
@ -53,9 +54,13 @@ class DomainMiddleware(BaseHTTPMiddleware):
else: else:
current_domain = cur_path.split('/')[0] current_domain = cur_path.split('/')[0]
if len(current_domain): try:
config_section = self.config.items(current_domain) config_section = self.config.items(current_domain)
scope_['config'] = dict(config_section) scope_['config'] = dict(config_section)
except configparser.NoSectionError:
logger.info(
f'No specific configuration for domain **{current_domain}**')
scope_['config'] = {}
request = Request(scope_, receive) request = Request(scope_, receive)