From 5ac911afe22147bf26ce381098cd929f62e074cd Mon Sep 17 00:00:00 2001 From: Keaton Taylor Date: Tue, 19 May 2020 12:23:18 -0500 Subject: [PATCH] improved error handling for catch all --- lambda_function.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lambda_function.py b/lambda_function.py index 67eca1d1..9ad717c9 100644 --- a/lambda_function.py +++ b/lambda_function.py @@ -345,15 +345,22 @@ def can_handle(self, handler_input, exception): def handle(self, handler_input, exception): print("CatchAllExceptionHandler") logger.error(exception, exc_info=True) - speak_output = "Sorry, I had trouble doing what you asked, or couldn't understand you. \ - Please try again." + home_assistant_object = HomeAssistant() + + if hasattr(home_assistant_object, 'ha_state') and home_assistant_object.ha_state != None and 'text' in home_assistant_object.ha_state: + return ( + handler_input.response_builder + .speak("Sorry I did not catch that... " + home_assistant_object.ha_state['text']) + .ask('') + .response + ) + else: + return ( + handler_input.response_builder + .speak("Sorry, I am having trouble, please check your configuration, in the custom skill and try again.") + .response + ) - return ( - handler_input.response_builder - .speak(speak_output) - .ask('') - .response - ) # The SkillBuilder object acts as the entry point for your skill, routing all request and response # payloads to the handlers above. Make sure any new handlers or interceptors you've