Code Monkey home page Code Monkey logo

Comments (3)

nikkopante avatar nikkopante commented on May 27, 2024 2

Ohhh nice! I did not notice I was using AbstractExceptionHandler.
I instead use the class CatchAccountLinkingErrorHandler(AbstractRequestHandler): as the easier implementation.

Again, thank you!

from alexa-skills-kit-sdk-for-python.

nikhilym avatar nikhilym commented on May 27, 2024 1

Glad it worked :-) !!

from alexa-skills-kit-sdk-for-python.

nikhilym avatar nikhilym commented on May 27, 2024

Hey @cnpants , your CatchAccountLinkingErrorHandler should be an implementation of AbstractRequestHandler class, considering you want to handle the input alexa request and respond with a custom message (similar to any of the request handler use cases). Just change the parent class of CatchAccountLinkingErrorHandler to

class CatchAccountLinkingErrorHandler(AbstractRequestHandler):

and register the request handler before any of the intent handlers, so that the SDK will respond before it checks other intents. (ref)

The exception handler will make sense in cases when you are not using checkAccessToken method in code but directly assuming there is an account token and using it. Considering there won't be an 'access_token' attribute in user if there is no account linking, you can have an exception handler like

class CatchAccountLinkingErrorHandler(AbstractExceptionHandler):
	def can_handle(self, handler_input, exception):
                # type: (HandlerInput, Exception) -> Response
                
                # considering there will be an attribute error for no access_token 
                # attribute found, when using
                # handler_input.request_envelope.session.user.access_token
		return type(exception).__name__ == 'AttributeError'

	def handle(self, handler_input, exception):
		# type: (HandlerInput, Exception) -> Response
		logger.info("In CatchAccountLinkingErrorHandler")
		
		handler_input.response_builder.speak("Your account is not linked.")

		return handler_input.response_builder.response

that catches such errors and responds back with a seamless message to the user. But be careful of the conditions being checked in the can_handle function. The above class would catch all attribute errors in your code, regardless of where it occurred hence gobbling up some other errors. So, add more conditions to the can_handle function accordingly.

I am not sure what error response your CatchAllExceptionHandler threw when you tried sb.add_exception_handler(CatchAccountLinkingErrorHandler()), but in case you want to use the class as ExceptionHandler, you need to register it before the CatchAllExceptionHandler so that specific exceptions are processed before generic exceptions. (ref)

Let us know if this helps. As for the stack overflow tag, I will check with the team on their inputs and update the repo if we plan to adding that.

from alexa-skills-kit-sdk-for-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.