Skip to content

Commit

Permalink
Merge pull request #46 from sidan-lab/main
Browse files Browse the repository at this point in the history
Fix: Error handling / TransactionDetail schema type
  • Loading branch information
Vardominator authored Apr 19, 2024
2 parents b7b8a7e + dd57081 commit fa0911f
Show file tree
Hide file tree
Showing 14 changed files with 185 additions and 2 deletions.
20 changes: 20 additions & 0 deletions client/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package client
import (
"encoding/json"
"fmt"
"net/http"

"github.com/maestro-org/go-sdk/models"
"github.com/maestro-org/go-sdk/utils"
Expand All @@ -21,6 +22,9 @@ func (c *Client) AccountAddresses(
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected error: %d", resp.Body)
}
defer resp.Body.Close()
var accountAddresses models.AccountAddresses
err = json.NewDecoder(resp.Body).Decode(&accountAddresses)
Expand All @@ -43,6 +47,9 @@ func (c *Client) AccountAssets(
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected error: %d", resp.Body)
}
defer resp.Body.Close()
var accountAssets models.AccountAssets
err = json.NewDecoder(resp.Body).Decode(&accountAssets)
Expand All @@ -65,6 +72,9 @@ func (c *Client) StakeAccountHistory(
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected error: %d", resp.Body)
}
defer resp.Body.Close()
var stakeAccountHistory models.StakeAccountHistory
err = json.NewDecoder(resp.Body).Decode(&stakeAccountHistory)
Expand All @@ -82,6 +92,10 @@ func (c *Client) StakeAccountInformation(
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected error: %d", resp.Body)
}

defer resp.Body.Close()
var stakeAccountInformation models.StakeAccountInformation
err = json.NewDecoder(resp.Body).Decode(&stakeAccountInformation)
Expand All @@ -104,6 +118,9 @@ func (c *Client) StakeAccountRewards(
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected error: %d", resp.Body)
}
defer resp.Body.Close()
var stakeAccountRewards models.StakeAccountRewards
err = json.NewDecoder(resp.Body).Decode(&stakeAccountRewards)
Expand All @@ -126,6 +143,9 @@ func (c *Client) StakeAccountUpdates(
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected error: %d", resp.Body)
}
defer resp.Body.Close()
var stakeAccountUpdates models.StakeAccountUpdates
err = json.NewDecoder(resp.Body).Decode(&stakeAccountUpdates)
Expand Down
25 changes: 25 additions & 0 deletions client/addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package client
import (
"encoding/json"
"fmt"
"net/http"

"github.com/maestro-org/go-sdk/models"
"github.com/maestro-org/go-sdk/utils"
Expand All @@ -14,6 +15,9 @@ func (c *Client) DecodeAddress(address string) (*models.DecodedAddress, error) {
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected error: %d", resp.Body)
}
defer resp.Body.Close()
var decodedAddress models.DecodedAddress
err = json.NewDecoder(resp.Body).Decode(&decodedAddress)
Expand All @@ -29,6 +33,9 @@ func (c *Client) AddressTransactionCount(address string) (*models.AddressTransac
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected error: %d", resp.Body)
}
defer resp.Body.Close()
var addressTransactionCount models.AddressTransactionCount
err = json.NewDecoder(resp.Body).Decode(&addressTransactionCount)
Expand All @@ -51,6 +58,9 @@ func (c *Client) AddressTransactions(
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected error: %d", resp.Body)
}
defer resp.Body.Close()
var addressTransactions models.AddressTransactions
err = json.NewDecoder(resp.Body).Decode(&addressTransactions)
Expand All @@ -73,6 +83,9 @@ func (c *Client) PaymentCredentialTransactions(
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected error: %d", resp.Body)
}
defer resp.Body.Close()
var addressTransactions models.AddressTransactions
err = json.NewDecoder(resp.Body).Decode(&addressTransactions)
Expand All @@ -95,6 +108,9 @@ func (c *Client) UtxoReferencesAtAddress(
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected error: %d", resp.Body)
}
defer resp.Body.Close()
var utxoReferencesAtAddress models.UtxoReferencesAtAddress
err = json.NewDecoder(resp.Body).Decode(&utxoReferencesAtAddress)
Expand All @@ -117,6 +133,9 @@ func (c *Client) UtxosAtAddress(
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected error: %d", resp.Body)
}
defer resp.Body.Close()
var utxosAtAddress models.UtxosAtAddress
err = json.NewDecoder(resp.Body).Decode(&utxosAtAddress)
Expand All @@ -140,6 +159,9 @@ func (c *Client) UtxosAtAddresses(
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected error: %d", resp.Body)
}
defer resp.Body.Close()
var utxosAtAddress models.UtxosAtAddress
err = json.NewDecoder(resp.Body).Decode(&utxosAtAddress)
Expand All @@ -162,6 +184,9 @@ func (c *Client) UtxosByPaymentCredential(
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected error: %d", resp.Body)
}
defer resp.Body.Close()
var utxosAtAddress models.UtxosAtAddress
err = json.NewDecoder(resp.Body).Decode(&utxosAtAddress)
Expand Down
19 changes: 19 additions & 0 deletions client/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package client
import (
"encoding/json"
"fmt"
"net/http"

"github.com/maestro-org/go-sdk/models"
"github.com/maestro-org/go-sdk/utils"
Expand All @@ -21,6 +22,9 @@ func (c *Client) AccountsHoldingAsset(
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected error: %d", resp.Body)
}
defer resp.Body.Close()
var accountsHoldingAsset models.AccountsHoldingAsset
err = json.NewDecoder(resp.Body).Decode(&accountsHoldingAsset)
Expand All @@ -43,6 +47,9 @@ func (c *Client) AddressHoldingAsset(
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected error: %d", resp.Body)
}
defer resp.Body.Close()
var addressesHoldingAsset models.AddressesHoldingAsset
err = json.NewDecoder(resp.Body).Decode(&addressesHoldingAsset)
Expand All @@ -58,6 +65,9 @@ func (c *Client) Asset(assetId string) (*models.AssetInformations, error) {
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected error: %d", resp.Body)
}
defer resp.Body.Close()
var assetInformation models.AssetInformations
err = json.NewDecoder(resp.Body).Decode(&assetInformation)
Expand All @@ -80,6 +90,9 @@ func (c *Client) AssetTransactions(
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected error: %d", resp.Body)
}
defer resp.Body.Close()
var assetTransactions models.AssetTransactions
err = json.NewDecoder(resp.Body).Decode(&assetTransactions)
Expand All @@ -102,6 +115,9 @@ func (c *Client) AssetUpdates(
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected error: %d", resp.Body)
}
defer resp.Body.Close()
var assetUpdates models.AssetUpdates
err = json.NewDecoder(resp.Body).Decode(&assetUpdates)
Expand All @@ -122,6 +138,9 @@ func (c *Client) AssetUtxos(assetId string, params *utils.Parameters) (*models.A
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected error: %d", resp.Body)
}
defer resp.Body.Close()
var assetUtxos models.AssetUtxos
err = json.NewDecoder(resp.Body).Decode(&assetUtxos)
Expand Down
16 changes: 16 additions & 0 deletions client/asset_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package client
import (
"encoding/json"
"fmt"
"net/http"

"github.com/maestro-org/go-sdk/models"
"github.com/maestro-org/go-sdk/utils"
Expand All @@ -21,6 +22,9 @@ func (c *Client) AccountsHoldingPolicy(
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected error: %d", resp.Body)
}
defer resp.Body.Close()
var response models.AccountsHoldingPolicy
err = json.NewDecoder(resp.Body).Decode(&response)
Expand All @@ -43,6 +47,9 @@ func (c *Client) AddressesHoldingPolicy(
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected error: %d", resp.Body)
}
defer resp.Body.Close()
var response models.AddressesHoldingPolicy
err = json.NewDecoder(resp.Body).Decode(&response)
Expand All @@ -65,6 +72,9 @@ func (c *Client) SpecificPolicyInformations(
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected error: %d", resp.Body)
}
defer resp.Body.Close()
var response models.PolicyInformation
err = json.NewDecoder(resp.Body).Decode(&response)
Expand All @@ -87,6 +97,9 @@ func (c *Client) TransactionsMovingPolicy(
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected error: %d", resp.Body)
}
defer resp.Body.Close()
var response models.PolicyTransactions
err = json.NewDecoder(resp.Body).Decode(&response)
Expand All @@ -109,6 +122,9 @@ func (c *Client) UtxosContainingPolicy(
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected error: %d", resp.Body)
}
defer resp.Body.Close()
var response models.UtxosContainingPolicy
err = json.NewDecoder(resp.Body).Decode(&response)
Expand Down
4 changes: 4 additions & 0 deletions client/datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package client
import (
"encoding/json"
"fmt"
"net/http"

"github.com/maestro-org/go-sdk/models"
)
Expand All @@ -13,6 +14,9 @@ func (c *Client) DatumFromHash(hash string) (*models.DatumFromHash, error) {
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected error: %d", resp.Body)
}
defer resp.Body.Close()
var datum models.DatumFromHash
err = json.NewDecoder(resp.Body).Decode(&datum)
Expand Down
4 changes: 4 additions & 0 deletions client/ecosystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package client
import (
"encoding/json"
"fmt"
"net/http"

"github.com/maestro-org/go-sdk/models"
)
Expand All @@ -13,6 +14,9 @@ func (c *Client) ResolveAdaHandle(handle string) (*models.BasicResponse, error)
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected error: %d", resp.Body)
}
defer resp.Body.Close()
var adaHandle models.BasicResponse
err = json.NewDecoder(resp.Body).Decode(&adaHandle)
Expand Down
7 changes: 7 additions & 0 deletions client/epochs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package client
import (
"encoding/json"
"fmt"
"net/http"

"github.com/maestro-org/go-sdk/models"
)
Expand All @@ -13,6 +14,9 @@ func (c *Client) CurrentEpoch() (*models.EpochResp, error) {
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected error: %d", resp.Body)
}
defer resp.Body.Close()
var currentEpoch models.EpochResp
err = json.NewDecoder(resp.Body).Decode(&currentEpoch)
Expand All @@ -28,6 +32,9 @@ func (c *Client) SpecificEpoch(epochNo int) (*models.EpochResp, error) {
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected error: %d", resp.Body)
}
defer resp.Body.Close()
var specificEpoch models.EpochResp
err = json.NewDecoder(resp.Body).Decode(&specificEpoch)
Expand Down
14 changes: 14 additions & 0 deletions client/general.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package client

import (
"encoding/json"
"fmt"
"net/http"

"github.com/maestro-org/go-sdk/models"
)
Expand All @@ -12,6 +14,9 @@ func (c *Client) ChainTip() (*models.ChainTip, error) {
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected error: %d", resp.Body)
}
defer resp.Body.Close()
var chainTip models.ChainTip
err = json.NewDecoder(resp.Body).Decode(&chainTip)
Expand All @@ -27,6 +32,9 @@ func (c *Client) EraHistory() (*models.EraHistory, error) {
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected error: %d", resp.Body)
}
defer resp.Body.Close()
var eraHistory models.EraHistory
err = json.NewDecoder(resp.Body).Decode(&eraHistory)
Expand All @@ -42,6 +50,9 @@ func (c *Client) ProtocolParameters() (*models.ProtocolParameters, error) {
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected error: %d", resp.Body)
}
defer resp.Body.Close()
var protocolParameters models.ProtocolParameters
err = json.NewDecoder(resp.Body).Decode(&protocolParameters)
Expand All @@ -57,6 +68,9 @@ func (c *Client) BlockChainStartTime() (models.BasicResponse, error) {
if err != nil {
return models.BasicResponse{}, err
}
if resp.StatusCode != http.StatusOK {
return models.BasicResponse{}, fmt.Errorf("unexpected error: %d", resp.Body)
}
defer resp.Body.Close()
var blockchainStartTime models.BasicResponse
err = json.NewDecoder(resp.Body).Decode(&blockchainStartTime)
Expand Down
Loading

0 comments on commit fa0911f

Please sign in to comment.