Skip to content

Commit

Permalink
Adjust function apiError to construct an ApiError.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanknowles committed Oct 29, 2022
1 parent 96e1f66 commit 616328d
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lib/wallet/api/http/Cardano/Wallet/Api/Http/Server/Error.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE TypeApplications #-}

Expand Down Expand Up @@ -73,7 +75,7 @@ import Cardano.Wallet
, ErrWrongPassphrase (..)
)
import Cardano.Wallet.Api.Types
( ApiErrorInfo (..), Iso8601Time (..) )
( ApiError (..), ApiErrorInfo (..), ApiErrorMessage (..), Iso8601Time (..) )
import Cardano.Wallet.CoinSelection
( SelectionBalanceError (..)
, SelectionCollateralError
Expand Down Expand Up @@ -101,8 +103,6 @@ import Control.Monad.Except
( ExceptT, withExceptT )
import Control.Monad.Trans.Except
( throwE )
import Data.Aeson
( (.=) )
import Data.Generics.Internal.VL
( view, (^.) )
import Data.List
Expand Down Expand Up @@ -162,15 +162,14 @@ liftE :: IsServerError e => e -> Handler a
liftE = liftHandler . throwE

apiError :: ServerError -> ApiErrorInfo -> Text -> ServerError
apiError err info message = err
{ errBody = Aeson.encode $ Aeson.object
[ "code" .= info
, "message" .= T.replace "\n" " " message
]
apiError err info messageUnformatted = err
{ errBody = Aeson.encode ApiError {info, message}
, errHeaders =
(hContentType, renderHeader $ contentType $ Proxy @JSON)
: errHeaders err
}
where
message = ApiErrorMessage (T.replace "\n" " " messageUnformatted)

err425 :: ServerError
err425 = ServerError 425 "Too early" "" []
Expand Down

0 comments on commit 616328d

Please sign in to comment.