Skip to content

Commit

Permalink
fix: error handling (#3809)
Browse files Browse the repository at this point in the history
## Overview

improve error handling
  • Loading branch information
ninabarbakadze authored Aug 22, 2024
1 parent e7a4b51 commit 3d90004
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions pkg/user/tx_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,10 @@ type BroadcastTxError struct {
Code uint32
// ErrorLog is the error output of the app's logger
ErrorLog string
// Err is the error that occurred during broadcasting
Err error
}

func (e *BroadcastTxError) Error() string {
return fmt.Sprintf("%v", e.Err)
return fmt.Sprintf("broadcast tx error: %s", e.ErrorLog)
}

// ExecutionError is an error that occurs when a transaction gets executed.
Expand All @@ -69,12 +67,10 @@ type ExecutionError struct {
Code uint32
// ErrorLog is the error output of the app's logger
ErrorLog string
// Err is the error that occurred during execution
Err error
}

func (e *ExecutionError) Error() string {
return fmt.Sprintf("%v", e.Err)
return fmt.Sprintf("tx execution failed with code %d: %s", e.Code, e.ErrorLog)
}

// WithGasMultiplier is a functional option allows to configure the gas multiplier.
Expand Down Expand Up @@ -385,7 +381,6 @@ func (client *TxClient) broadcastTx(ctx context.Context, txBytes []byte, signer
broadcastTxErr := &BroadcastTxError{
TxHash: resp.TxResponse.TxHash,
Code: resp.TxResponse.Code,
Err: fmt.Errorf("tx failed with code %d: %s", resp.TxResponse.Code, resp.TxResponse.RawLog),
ErrorLog: resp.TxResponse.RawLog,
}
return resp.TxResponse, broadcastTxErr
Expand Down Expand Up @@ -489,7 +484,6 @@ func (client *TxClient) ConfirmTx(ctx context.Context, txHash string) (*TxRespon
TxHash: txHash,
Code: resp.ExecutionCode,
ErrorLog: resp.Error,
Err: fmt.Errorf("execution failed with code %d", resp.ExecutionCode),
}
return nil, executionErr
}
Expand Down

0 comments on commit 3d90004

Please sign in to comment.