Skip to content

Commit

Permalink
Move API error types to Cardano.Wallet.Api.Types.Error.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanknowles committed Oct 29, 2022
1 parent f67247d commit 63ffa4a
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 160 deletions.
3 changes: 2 additions & 1 deletion lib/wallet/api/http/Cardano/Wallet/Api/Http/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ import Cardano.Wallet.Api.Types
, ApiAddressInspectData (..)
, ApiCredential (..)
, ApiDelegationAction (..)
, ApiErrorInfo (..)
, ApiHealthCheck (..)
, ApiMaintenanceAction (..)
, ApiMaintenanceActionPostData (..)
Expand All @@ -166,6 +165,8 @@ import Cardano.Wallet.Api.Types
)
import Cardano.Wallet.Api.Types.BlockHeader
( ApiBlockHeader )
import Cardano.Wallet.Api.Types.Error
( ApiErrorInfo (..) )
import Cardano.Wallet.Api.Types.SchemaMetadata
( TxMetadataSchema (..), parseSimpleMetadataFlag )
import Cardano.Wallet.Primitive.AddressDerivation
Expand Down
3 changes: 2 additions & 1 deletion lib/wallet/api/http/Cardano/Wallet/Api/Http/Server/Error.hs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ import Cardano.Wallet
, ErrWrongPassphrase (..)
)
import Cardano.Wallet.Api.Types
( Iso8601Time (..) )
import Cardano.Wallet.Api.Types.Error
( ApiError (..)
, ApiErrorInfo (..)
, ApiErrorMessage (..)
, ApiErrorTxOutputLovelaceInsufficient (..)
, Iso8601Time (..)
)
import Cardano.Wallet.CoinSelection
( SelectionBalanceError (..)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Prelude hiding

import Cardano.Wallet.Api.Http.Server.Error
( IsServerError (..), apiError, liftE, showT )
import Cardano.Wallet.Api.Types
import Cardano.Wallet.Api.Types.Error
( ApiErrorInfo (UnexpectedError) )
import Cardano.Wallet.Primitive.Types
( Certificate )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ import Cardano.Wallet.Api.Types
, ApiConstructTransaction (..)
, ApiConstructTransactionData (..)
, ApiDecodedTransaction (..)
, ApiErrorInfo (..)
, ApiExternalInput (..)
, ApiFee (..)
, ApiForeignStakeKey (..)
Expand Down Expand Up @@ -321,6 +320,8 @@ import Cardano.Wallet.Api.Types.BlockHeader
( ApiBlockHeader, mkApiBlockHeader )
import Cardano.Wallet.Api.Types.Certificate
( mkApiAnyCertificate )
import Cardano.Wallet.Api.Types.Error
( ApiErrorInfo (..) )
import Cardano.Wallet.Api.Types.Key
( computeKeyPayload )
import Cardano.Wallet.Api.Types.MintBurn
Expand Down
150 changes: 0 additions & 150 deletions lib/wallet/api/http/Cardano/Wallet/Api/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ module Cardano.Wallet.Api.Types
, ApiDeregisterPool (..)
, ApiEra (..)
, ApiEraInfo (..)
, ApiError (..)
, ApiErrorInfo (..)
, ApiErrorMessage (..)
, ApiErrorTxOutputLovelaceInsufficient (..)
, ApiExternalCertificate (..)
, ApiExternalInput (..)
, ApiFee (..)
Expand Down Expand Up @@ -407,8 +403,6 @@ import Control.DeepSeq
( NFData (..) )
import Control.Monad
( guard, when, (<=<), (>=>) )
import Data.Aeson.Extra
( objectUnion )
import Data.Aeson.Types
( FromJSON (..)
, Parser
Expand Down Expand Up @@ -440,8 +434,6 @@ import Data.ByteString
( ByteString )
import Data.Char
( toLower )
import Data.Data
( Data )
import Data.Either.Combinators
( maybeToRight )
import Data.Either.Extra
Expand All @@ -460,8 +452,6 @@ import Data.List.NonEmpty
( NonEmpty (..) )
import Data.Map.Strict
( Map )
import Data.Maybe
( fromMaybe )
import Data.Proxy
( Proxy (..) )
import Data.Quantity
Expand Down Expand Up @@ -1656,146 +1646,6 @@ data ApiSharedWalletPatchData = ApiSharedWalletPatchData
deriving (Eq, Generic, Show)
deriving anyclass NFData

data ApiError = ApiError
{ info :: !ApiErrorInfo
, message :: !ApiErrorMessage
}
deriving (Eq, Generic, Show)
deriving anyclass NFData

instance ToJSON ApiError where
toJSON ApiError {info, message}
= fromMaybe (error "ToJSON ApiError: Unexpected encoding")
$ toJSON info `objectUnion` toJSON message

instance FromJSON ApiError where
parseJSON o = ApiError <$> parseJSON o <*> parseJSON o

newtype ApiErrorMessage = ApiErrorMessage {message :: Text}
deriving (Eq, Generic, Show)
deriving (FromJSON, ToJSON) via DefaultRecord ApiErrorMessage
deriving anyclass NFData

data ApiErrorInfo
= AddressAlreadyExists
| AlreadyWithdrawing
| AssetNameTooLong
| AssetNotPresent
| BadRequest
| BalanceTxEraNotSupported
| BalanceTxInlineDatumsNotSupportedInAlonzo
| BalanceTxInlineScriptsNotSupportedInAlonzo
| BalanceTxConflictingNetworks
| BalanceTxExistingCollateral
| BalanceTxExistingKeyWitnesses
| BalanceTxExistingReturnCollateral
| BalanceTxExistingTotalCollateral
| BalanceTxInternalError
| BalanceTxMaxSizeLimitExceeded
| BalanceTxUnderestimatedFee
| BalanceTxZeroAdaOutput
| CannotCoverFee
| CreatedInvalidTransaction
| CreatedMultiaccountTransaction
| CreatedMultidelegationTransaction
| CreatedWrongPolicyScriptTemplate
| ExistingKeyWitnesses
| ForeignTransaction
| HardenedDerivationRequired
| InputsDepleted
| InsufficientCollateral
| InvalidCoinSelection
| InvalidWalletType
| InvalidValidityBounds
| KeyNotFoundForAddress
| MalformedTxPayload
| MempoolIsFull
| MethodNotAllowed
| MinWithdrawalWrong
| MintOrBurnAssetQuantityOutOfBounds
| MissingPolicyPublicKey
| MissingWitnessesInTransaction
| NetworkMisconfigured
| NetworkQueryFailed
| NetworkUnreachable
| NoRootKey
| NoSuchPool
| NoSuchTransaction
| NoSuchWallet
| NonNullRewards
| NotAcceptable
| NotDelegatingTo
| NotEnoughMoney
| NotFound
| NotImplemented
| NotSynced
| NothingToMigrate
| OutputTokenBundleSizeExceedsLimit
| OutputTokenQuantityExceedsLimit
| PastHorizon
| PoolAlreadyJoined
| QueryParamMissing
| RedeemerInvalidData
| RedeemerScriptFailure
| RedeemerTargetNotFound
| RejectedByCoreNode
| SharedWalletCannotUpdateKey
| SharedWalletKeyAlreadyExists
| SharedWalletNoDelegationTemplate
| SharedWalletNoSuchCosigner
| SharedWalletNotPending
| SharedWalletPending
| SharedWalletScriptTemplateInvalid
| SoftDerivationRequired
| StartTimeLaterThanEndTime
| TokensMintedButNotSpentOrBurned
| TransactionAlreadyBalanced
| TransactionAlreadyInLedger
| TransactionIsTooBig
| TranslationError
| UnableToAssignInputOutput
| UnableToDetermineCurrentEpoch
| UnexpectedError
| UnresolvedInputs
| InputResolutionConflicts
| UnsupportedMediaType
| UtxoTooSmall ApiErrorTxOutputLovelaceInsufficient
| WalletAlreadyExists
| WalletNotResponding
| WithdrawalNotWorth
| WrongEncryptionPassphrase
| WrongMnemonic
| ValidityIntervalNotInsideScriptTimelock
deriving (Eq, Generic, Show, Data, Typeable)
deriving anyclass NFData

instance FromJSON ApiErrorInfo where
parseJSON = genericParseJSON apiErrorInfoOptions

instance ToJSON ApiErrorInfo where
toJSON = genericToJSON apiErrorInfoOptions

apiErrorInfoOptions :: Aeson.Options
apiErrorInfoOptions = defaultSumTypeOptions
{ sumEncoding = TaggedObject
{ tagFieldName = "code"
, contentsFieldName = "info"
}
}

data ApiErrorTxOutputLovelaceInsufficient = ApiErrorTxOutputLovelaceInsufficient
{ txOutputIndex
:: !Word32
, txOutputLovelaceSpecified
:: !(Quantity "lovelace" Natural)
, txOutputLovelaceRequiredMinimum
:: !(Quantity "lovelace" Natural)
}
deriving (Data, Eq, Generic, Show, Typeable)
deriving (FromJSON, ToJSON)
via DefaultRecord ApiErrorTxOutputLovelaceInsufficient
deriving anyclass NFData

-- | Defines a point in time that can be formatted as and parsed from an
-- ISO 8601-compliant string.
--
Expand Down

0 comments on commit 63ffa4a

Please sign in to comment.