How to use exception_mapper method in localstack

Best Python code snippet using localstack_python

skill.py

Source:skill.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2#3# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights4# Reserved.5#6# Licensed under the Apache License, Version 2.0 (the "License").7# You may not use this file except in compliance with the License.8# A copy of the License is located at9#10# http://aws.amazon.com/apache2.0/11#12# or in the "license" file accompanying this file. This file is13# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS14# OF ANY KIND, either express or implied. See the License for the15# specific language governing permissions and limitations under the16# License.17#18import typing19from ask_sdk_model.services import ServiceClientFactory, ApiConfiguration20from ask_sdk_model import ResponseEnvelope21from .dispatch import RequestDispatcher22from .serialize import DefaultSerializer23from .handler_input import HandlerInput24from .exceptions import AskSdkException25from .attributes_manager import AttributesManager26from .utils import user_agent_info, RESPONSE_FORMAT_VERSION27if typing.TYPE_CHECKING:28 from typing import List, TypeVar, Any29 from ask_sdk_model.services import ApiClient30 from ask_sdk_model import RequestEnvelope31 from .dispatch_components import (32 RequestMapper, HandlerAdapter, ExceptionMapper,33 AbstractRequestInterceptor, AbstractResponseInterceptor)34 T = TypeVar['T']35class SkillConfiguration(object):36 """Configuration Object that represents standard components37 needed to build :py:class:`Skill`.38 :param request_mappers: List of request mapper instances.39 :type request_mappers: list(RequestMapper)40 :param handler_adapters: List of handler adapter instances.41 :type handler_adapters: list(HandlerAdapter)42 :param request_interceptors: List of43 request interceptor instances.44 :type request_interceptors: list(AbstractRequestInterceptor)45 :param response_interceptors: List of46 response interceptor instances.47 :type response_interceptors: list(AbstractResponseInterceptor)48 :param exception_mapper: Exception mapper instance.49 :type exception_mapper: ExceptionMapper50 :param persistence_adapter: Persistence adapter instance.51 :type persistence_adapter: AbstractPersistenceAdapter52 :param api_client: Api Client instance.53 :type api_client: ask_sdk_model.services.api_client.ApiClient54 :param custom_user_agent: Custom User Agent string55 :type custom_user_agent: str56 :param skill_id: ID of the skill.57 :type skill_id: str58 """59 def __init__(60 self, request_mappers, handler_adapters,61 request_interceptors=None, response_interceptors=None,62 exception_mapper=None, persistence_adapter=None,63 api_client=None, custom_user_agent=None, skill_id=None):64 # type: (List[RequestMapper], List[HandlerAdapter], List[AbstractRequestInterceptor], List[AbstractResponseInterceptor], ExceptionMapper, PersistenceAdapter, ApiClient, str, str) -> None65 """Configuration object that represents standard components66 needed for building :py:class:`Skill`.67 :param request_mappers: List of request mapper instances.68 :type request_mappers: list(RequestMapper)69 :param handler_adapters: List of handler adapter instances.70 :type handler_adapters: list(HandlerAdapter)71 :param request_interceptors: List of72 request interceptor instances.73 :type request_interceptors: list(AbstractRequestInterceptor)74 :param response_interceptors: List of75 response interceptor instances.76 :type response_interceptors: list(AbstractResponseInterceptor)77 :param exception_mapper: Exception mapper instance.78 :type exception_mapper: ExceptionMapper79 :param persistence_adapter: Persistence adapter instance.80 :type persistence_adapter: AbstractPersistenceAdapter81 :param api_client: Api Client instance.82 :type api_client: ask_sdk_model.services.api_client.ApiClient83 :param custom_user_agent: Custom User Agent string84 :type custom_user_agent: str85 :param skill_id: ID of the skill.86 :type skill_id: str87 """88 if request_mappers is None:89 request_mappers = []90 self.request_mappers = request_mappers91 if handler_adapters is None:92 handler_adapters = []93 self.handler_adapters = handler_adapters94 if request_interceptors is None:95 request_interceptors = []96 self.request_interceptors = request_interceptors97 if response_interceptors is None:98 response_interceptors = []99 self.response_interceptors = response_interceptors100 self.exception_mapper = exception_mapper101 self.persistence_adapter = persistence_adapter102 self.api_client = api_client103 self.custom_user_agent = custom_user_agent104 self.skill_id = skill_id105class Skill(object):106 """Top level container for Request Dispatcher,107 Persistence Adapter and Api Client.108 :param skill_configuration: Configuration object that holds109 information about different components needed to build the110 skill object.111 :type skill_configuration: SkillConfiguration112 """113 def __init__(self, skill_configuration):114 # type: (SkillConfiguration) -> None115 """Top level container for Request Dispatcher,116 Persistence Adapter and Api Client.117 :param skill_configuration: Configuration object that holds118 information about different components needed to build the119 skill object.120 :type skill_configuration: SkillConfiguration121 """122 self.persistence_adapter = skill_configuration.persistence_adapter123 self.api_client = skill_configuration.api_client124 self.serializer = DefaultSerializer()125 self.skill_id = skill_configuration.skill_id126 self.custom_user_agent = skill_configuration.custom_user_agent127 self.request_dispatcher = RequestDispatcher(128 request_mappers=skill_configuration.request_mappers,129 handler_adapters=skill_configuration.handler_adapters,130 exception_mapper=skill_configuration.exception_mapper,131 request_interceptors=skill_configuration.request_interceptors,132 response_interceptors=skill_configuration.response_interceptors)133 def invoke(self, request_envelope, context):134 # type: (RequestEnvelope, T) -> ResponseEnvelope135 """Invokes the dispatcher, to handle the request envelope and136 return a response envelope.137 :param request_envelope: Request Envelope instance containing138 request information139 :type request_envelope: RequestEnvelope140 :param context: Context passed during invocation141 :type context: Any142 :return: Response Envelope generated by handling the request143 :rtype: ResponseEnvelope144 """145 if (self.skill_id is not None and146 request_envelope.context.system.application.application_id !=147 self.skill_id):148 raise AskSdkException("Skill ID Verification failed!!")149 if self.api_client is not None:150 api_token = request_envelope.context.system.api_access_token151 api_endpoint = request_envelope.context.system.api_endpoint152 api_configuration = ApiConfiguration(153 serializer=self.serializer, api_client=self.api_client,154 authorization_value=api_token,155 api_endpoint=api_endpoint)156 factory = ServiceClientFactory(api_configuration=api_configuration)157 else:158 factory = None159 attributes_manager = AttributesManager(160 request_envelope=request_envelope,161 persistence_adapter=self.persistence_adapter)162 handler_input = HandlerInput(163 request_envelope=request_envelope,164 attributes_manager=attributes_manager,165 context=context,166 service_client_factory=factory)167 response = self.request_dispatcher.dispatch(handler_input)168 session_attributes = None169 if request_envelope.session is not None:170 session_attributes = (171 handler_input.attributes_manager.session_attributes)172 return ResponseEnvelope(173 response=response, version=RESPONSE_FORMAT_VERSION,174 session_attributes=session_attributes,...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful