WS: Improve service calling errors (#23840)

* WS: Improve service calling errors

* Docstyle

* Types

* Update text
This commit is contained in:
Paulus Schoutsen
2019-05-14 07:09:11 +02:00
committed by GitHub
parent 0d96095646
commit de1fd5a7fa
6 changed files with 68 additions and 8 deletions

View File

@@ -120,17 +120,21 @@ async def handle_call_service(hass, connection, msg):
msg['domain'], msg['service'], msg.get('service_data'), blocking,
connection.context(msg))
connection.send_message(messages.result_message(msg['id']))
except ServiceNotFound:
connection.send_message(messages.error_message(
msg['id'], const.ERR_NOT_FOUND, 'Service not found.'))
except ServiceNotFound as err:
if err.domain == msg['domain'] and err.service == msg['service']:
connection.send_message(messages.error_message(
msg['id'], const.ERR_NOT_FOUND, 'Service not found.'))
else:
connection.send_message(messages.error_message(
msg['id'], const.ERR_HOME_ASSISTANT_ERROR, str(err)))
except HomeAssistantError as err:
connection.logger.exception(err)
connection.send_message(messages.error_message(
msg['id'], const.ERR_HOME_ASSISTANT_ERROR, '{}'.format(err)))
msg['id'], const.ERR_HOME_ASSISTANT_ERROR, str(err)))
except Exception as err: # pylint: disable=broad-except
connection.logger.exception(err)
connection.send_message(messages.error_message(
msg['id'], const.ERR_UNKNOWN_ERROR, '{}'.format(err)))
msg['id'], const.ERR_UNKNOWN_ERROR, str(err)))
@callback