Skip to content

Commit d6abc77

Browse files
committed
chore: improved error handling for sdkClient
Signed-off-by: Logan Nguyen <logan.nguyen@swirldslabs.com>
1 parent 615e40b commit d6abc77

File tree

1 file changed

+7
-24
lines changed

1 file changed

+7
-24
lines changed

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

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -454,35 +454,18 @@ 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+
457459
this.logger.warn(
458-
e,
459-
`${requestDetails.formattedRequestId} Transaction failed while executing transaction via the SDK: transactionId=${transaction.transactionId}, callerName=${callerName}, txConstructorName=${txConstructorName}`,
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}`,
460461
);
461462

462-
if (e instanceof JsonRpcError) {
463-
throw e;
464-
}
465-
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;
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;
472466
}
473467

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;
468+
throw sdkClientError;
486469
} finally {
487470
if (transactionId?.length) {
488471
this.eventEmitter.emit(constants.EVENTS.EXECUTE_TRANSACTION, {

0 commit comments

Comments
 (0)