Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1bd72ea

Browse files
committed
AWS Service handlers:move NotImplementedError handling from skeleton to service
1 parent 38aecc7 commit 1bd72ea

File tree

2 files changed

+4
-37
lines changed

2 files changed

+4
-37
lines changed

‎localstack-core/localstack/aws/handlers/service.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from localstack.http import Response
1212
from localstack.utils.coverage_docs import get_coverage_link_for_service
1313

14+
from ...utils import analytics
1415
from ..api import CommonServiceException, RequestContext, ServiceException
1516
from ..api.core import ServiceOperation
1617
from ..chain import CompositeResponseHandler, ExceptionHandler, Handler, HandlerChain
@@ -178,6 +179,9 @@ def create_exception_response(self, exception: Exception, context: RequestContex
178179
message = exception_message or get_coverage_link_for_service(service_name, action_name)
179180
LOG.info(message)
180181
error = CommonServiceException("InternalFailure", message, status_code=501)
182+
analytics.log.event(
183+
"services_notimplemented", payload={"s": service_name, "a": action_name}
184+
)
181185
context.service_exception = error
182186

183187
elif not isinstance(exception, ServiceException):

‎localstack-core/localstack/aws/skeleton.py‎

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from botocore.model import ServiceModel
88

99
from localstack.aws.api import (
10-
CommonServiceException,
1110
RequestContext,
1211
ServiceException,
1312
)
@@ -16,8 +15,6 @@
1615
from localstack.aws.protocol.serializer import ResponseSerializer, create_serializer
1716
from localstack.aws.spec import load_service
1817
from localstack.http import Response
19-
from localstack.utils import analytics
20-
from localstack.utils.coverage_docs import get_coverage_link_for_service
2118

2219
LOG = logging.getLogger(__name__)
2320

@@ -153,8 +150,6 @@ def invoke(self, context: RequestContext) -> Response:
153150
return self.dispatch_request(serializer, context, instance)
154151
except ServiceException as e:
155152
return self.on_service_exception(serializer, context, e)
156-
except NotImplementedError as e:
157-
return self.on_not_implemented_error(serializer, context, e)
158153

159154
def dispatch_request(
160155
self, serializer: ResponseSerializer, context: RequestContext, instance: ServiceRequest
@@ -193,35 +188,3 @@ def on_service_exception(
193188
return serializer.serialize_error_to_response(
194189
exception, context.operation, context.request.headers, context.request_id
195190
)
196-
197-
def on_not_implemented_error(
198-
self,
199-
serializer: ResponseSerializer,
200-
context: RequestContext,
201-
exception: NotImplementedError,
202-
) -> Response:
203-
"""
204-
Called by invoke if either the dispatch table did not contain an entry for the operation, or the service
205-
provider raised a NotImplementedError
206-
:param serializer: the serialzier which should be used to serialize the NotImplementedError
207-
:param context: the request context
208-
:param exception: the NotImplementedError that was raised
209-
:return: a Response object
210-
"""
211-
operation = context.operation
212-
213-
action_name = operation.name
214-
service_name = operation.service_model.service_name
215-
exception_message: str | None = exception.args[0] if exception.args else None
216-
message = exception_message or get_coverage_link_for_service(service_name, action_name)
217-
LOG.info(message)
218-
error = CommonServiceException("InternalFailure", message, status_code=501)
219-
# record event
220-
analytics.log.event(
221-
"services_notimplemented", payload={"s": service_name, "a": action_name}
222-
)
223-
context.service_exception = error
224-
225-
return serializer.serialize_error_to_response(
226-
error, operation, context.request.headers, context.request_id
227-
)

0 commit comments

Comments
 (0)