Skip to content

Commit 98a8c8c

Browse files
Remove manual error classification
1 parent 44ec591 commit 98a8c8c

File tree

1 file changed

+1
-46
lines changed

1 file changed

+1
-46
lines changed

codegen/core/src/main/java/software/amazon/smithy/python/codegen/ClientGenerator.java

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -148,55 +148,13 @@ private void generateOperationExecutor(PythonWriter writer) {
148148
"OutputContext",
149149
"RequestContext",
150150
"ResponseContext"));
151-
writer.addImports("smithy_core.interfaces.retries", Set.of("RetryErrorInfo", "RetryErrorType"));
152151
writer.addImport("smithy_core.interfaces.exceptions", "HasFault");
153152
writer.addImport("smithy_core.types", "TypedProperties");
154153
writer.addImport("smithy_core.serializers", "SerializeableShape");
155154
writer.addImport("smithy_core.deserializers", "DeserializeableShape");
156155
writer.addImport("smithy_core.schemas", "APIOperation");
157-
158-
writer.indent();
159-
writer.write("""
160-
def _classify_error(
161-
self,
162-
*,
163-
error: Exception,
164-
context: ResponseContext[Any, $1T, $2T | None]
165-
) -> RetryErrorInfo:
166-
logger.debug("Classifying error: %s", error)
167-
""", transportRequest, transportResponse);
168156
writer.indent();
169157

170-
if (context.applicationProtocol().isHttpProtocol()) {
171-
writer.addDependency(SmithyPythonDependency.SMITHY_HTTP);
172-
writer.write("""
173-
if not isinstance(error, HasFault) and not context.transport_response:
174-
return RetryErrorInfo(error_type=RetryErrorType.TRANSIENT)
175-
176-
if context.transport_response:
177-
if context.transport_response.status in [429, 503]:
178-
retry_after = None
179-
retry_header = context.transport_response.fields["retry-after"]
180-
if retry_header and retry_header.values:
181-
retry_after = float(retry_header.values[0])
182-
return RetryErrorInfo(error_type=RetryErrorType.THROTTLING, retry_after_hint=retry_after)
183-
184-
if context.transport_response.status >= 500:
185-
return RetryErrorInfo(error_type=RetryErrorType.SERVER_ERROR)
186-
187-
""");
188-
}
189-
190-
writer.write("""
191-
error_type = RetryErrorType.CLIENT_ERROR
192-
if isinstance(error, HasFault) and error.fault == "server":
193-
error_type = RetryErrorType.SERVER_ERROR
194-
195-
return RetryErrorInfo(error_type=error_type)
196-
197-
""");
198-
writer.dedent();
199-
200158
if (hasStreaming) {
201159
writer.addStdlibImports("typing", Set.of("Any", "Awaitable"));
202160
writer.addStdlibImport("asyncio");
@@ -425,10 +383,7 @@ def _classify_error(
425383
try:
426384
retry_token = retry_strategy.refresh_retry_token_for_retry(
427385
token_to_renew=retry_token,
428-
error_info=self._classify_error(
429-
error=output_context.response,
430-
context=output_context,
431-
)
386+
error=output_context.response,
432387
)
433388
except SmithyRetryException:
434389
raise output_context.response

0 commit comments

Comments
 (0)