Display error message instead of exception (#4866)

* Display error message instead of exception

Display error message in log instead of stack trace.
(Usually happens when a server is already running at the same port.)

* Update __init__.py

Better error handling when reading SSL certificate

* Update __init__.py

* Update __init__.py
This commit is contained in:
Erik Eriksson 2016-12-13 07:02:24 +01:00 committed by Paulus Schoutsen
parent dbb4e4c3fa
commit 12f790c7cf

View File

@ -288,10 +288,16 @@ class HomeAssistantWSGI(object):
cors_added.add(route) cors_added.add(route)
if self.ssl_certificate: if self.ssl_certificate:
try:
context = ssl.SSLContext(SSL_VERSION) context = ssl.SSLContext(SSL_VERSION)
context.options |= SSL_OPTS context.options |= SSL_OPTS
context.set_ciphers(CIPHERS) context.set_ciphers(CIPHERS)
context.load_cert_chain(self.ssl_certificate, self.ssl_key) context.load_cert_chain(self.ssl_certificate, self.ssl_key)
except OSError as error:
_LOGGER.error("Could not read SSL certificate from %s: %s",
self.ssl_certificate, error)
context = None
return
else: else:
context = None context = None
@ -305,8 +311,12 @@ class HomeAssistantWSGI(object):
self._handler = self.app.make_handler() self._handler = self.app.make_handler()
try:
self.server = yield from self.hass.loop.create_server( self.server = yield from self.hass.loop.create_server(
self._handler, self.server_host, self.server_port, ssl=context) self._handler, self.server_host, self.server_port, ssl=context)
except OSError as error:
_LOGGER.error("Failed to create HTTP server at port %d: %s",
self.server_port, error)
self.app._frozen = False # pylint: disable=protected-access self.app._frozen = False # pylint: disable=protected-access