Merge pull request #1342 from hramezani/load_config_file_syntax_error

Handle syntax error in load config file.
This commit is contained in:
Stephen Sadowski
2018-10-11 08:56:48 -05:00
committed by GitHub
3 changed files with 21 additions and 0 deletions

View File

@@ -1,6 +1,8 @@
import os
import types
from sanic.exceptions import PyFileError
SANIC_PREFIX = 'SANIC_'
@@ -83,6 +85,9 @@ class Config(dict):
except IOError as e:
e.strerror = 'Unable to load configuration file (%s)' % e.strerror
raise
except Exception as e:
raise PyFileError(filename) from e
self.from_object(module)
return True

View File

@@ -223,6 +223,11 @@ class InvalidRangeType(ContentRangeError):
pass
class PyFileError(Exception):
def __init__(self, file):
super().__init__('could not execute config file %s', file)
@add_status_code(401)
class Unauthorized(SanicException):
"""