From 934b41dbe71ff8963f62d0fa23ddf6d6fa3f6f82 Mon Sep 17 00:00:00 2001 From: Rohit Durvasula Date: Mon, 2 Dec 2024 14:37:52 -0800 Subject: [PATCH] Better error handling between SDK and API. --- CHANGELOG.md | 12 +++++++++++- pkg/auth/transport.go | 2 +- pkg/coinbase/staking_operation.go | 5 +++++ pkg/errors/errors.go | 4 ++-- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0785552..e5c077a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ ## Unreleased +## [0.0.15] - 2024-12-02 + +### Added + +- Add `WithIntegratorContractAddress` to allow for setting an explicit integrator contract address for Shared ETH staking. + +### Fixed + +- Better error handling between the SDK and the API. + ## [0.0.14] - 2024-11-26 ### Added @@ -21,7 +31,7 @@ - Added constants for supported network names - Added `IsFailedState` and `IsCompleteState` methods to `StakingOperation` to check if the operation is in a failed or complete state -### Changes +### Changed - Exposed `IsTerminalState` method on `StakingOperation` to check if the operation is in a terminal state. diff --git a/pkg/auth/transport.go b/pkg/auth/transport.go index 0ea79ca..1f6db8f 100644 --- a/pkg/auth/transport.go +++ b/pkg/auth/transport.go @@ -36,7 +36,7 @@ func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) { "Correlation-Context", fmt.Sprintf( "%s,%s", - fmt.Sprintf("%s=%s", "sdk_version", "0.0.14"), + fmt.Sprintf("%s=%s", "sdk_version", "0.0.15"), fmt.Sprintf("%s=%s", "sdk_language", "go"), ), ) diff --git a/pkg/coinbase/staking_operation.go b/pkg/coinbase/staking_operation.go index a2150fa..e9a0dd7 100644 --- a/pkg/coinbase/staking_operation.go +++ b/pkg/coinbase/staking_operation.go @@ -22,6 +22,11 @@ func WithStakingOperationMode(mode string) StakingOperationOption { return WithStakingOperationOption("mode", mode) } +// WithIntegratorContractAddress allows for the setting of the integrator contract address for Shared ETH staking. +func WithIntegratorContractAddress(integratorContractAddress string) StakingOperationOption { + return WithStakingOperationOption("integrator_contract_address", integratorContractAddress) +} + // WithStakingOperationOption allows for the passing of custom options // to the staking operation, like `mode` or `withdrawal_address`. func WithStakingOperationOption(optionKey, optionValue string) StakingOperationOption { diff --git a/pkg/errors/errors.go b/pkg/errors/errors.go index d882122..f914623 100644 --- a/pkg/errors/errors.go +++ b/pkg/errors/errors.go @@ -49,10 +49,10 @@ func MapToUserFacing(err error, resp *http.Response) error { var openAPIError *client.GenericOpenAPIError if errors.As(err, &openAPIError) { var clientError client.Error - if err := clientError.UnmarshalJSON(openAPIError.Body()); err != nil { + if unmarshalErr := clientError.UnmarshalJSON(openAPIError.Body()); unmarshalErr != nil { return &APIError{ Code: "unknown", - Message: err.Error(), + Message: err.Error(), // relay back the original error message as is. } }