Skip to content

Commit 4c0e41d

Browse files
committed
Revert "chore: improved error handling for sdkClient"
This reverts commit 2dc2ff5. Signed-off-by: Logan Nguyen <[email protected]>
1 parent 2e8af99 commit 4c0e41d

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

packages/relay/src/lib/clients/sdkClient.ts

+24-7
Original file line numberDiff line numberDiff line change
@@ -454,18 +454,35 @@ export class SDKClient {
454454
);
455455
return transactionResponse;
456456
} catch (e: any) {
457-
const sdkClientError = new SDKClientError(e, e.message, transaction.transactionId?.toString(), e.nodeAccountId);
458-
459457
this.logger.warn(
460-
`${requestDetails.formattedRequestId} Failed to execute transaction via the SDK: transactionId=${transaction.transactionId}, callerName=${callerName}, txConstructorName=${txConstructorName}, errorStatus=${sdkClientError.status}(${sdkClientError.status._code}), errorMessage=${sdkClientError.message}, nodeId=${sdkClientError.nodeAccountId}`,
458+
e,
459+
`${requestDetails.formattedRequestId} Transaction failed while executing transaction via the SDK: transactionId=${transaction.transactionId}, callerName=${callerName}, txConstructorName=${txConstructorName}`,
461460
);
462461

463-
// In some cases, for instance, when the SDK returns a WRONG_NONCE error, the SDK still returns a valid transactionResponse.
464-
if (transactionResponse) {
465-
return transactionResponse;
462+
if (e instanceof JsonRpcError) {
463+
throw e;
466464
}
467465

468-
throw sdkClientError;
466+
const sdkClientError = new SDKClientError(e, e.message, transaction.transactionId?.toString(), e.nodeAccountId);
467+
468+
// WRONG_NONCE is one of the special errors where the SDK still returns a valid transactionResponse.
469+
// Throw the WRONG_NONCE error, as additional handling logic is expected in a higher layer.
470+
if (sdkClientError.status && sdkClientError.status === Status.WrongNonce) {
471+
throw sdkClientError;
472+
}
473+
474+
if (!transactionResponse) {
475+
// Transactions may experience "SDK timeout exceeded" or "Connection Dropped" errors from the SDK, yet they may still be able to reach the consensus layer.
476+
// Throw Connection Drop and Timeout errors as additional handling logic is expected in a higher layer.
477+
if (sdkClientError.isConnectionDropped() || sdkClientError.isTimeoutExceeded()) {
478+
throw sdkClientError;
479+
} else {
480+
throw predefined.INTERNAL_ERROR(
481+
`${requestDetails.formattedRequestId} Transaction execution returns a null value: transactionId=${transaction.transactionId}, callerName=${callerName}, txConstructorName=${txConstructorName}`,
482+
);
483+
}
484+
}
485+
return transactionResponse;
469486
} finally {
470487
if (transactionId?.length) {
471488
this.eventEmitter.emit(constants.EVENTS.EXECUTE_TRANSACTION, {

0 commit comments

Comments
 (0)