Skip to content

Commit

Permalink
added AppError JSON structures (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
martyall authored Dec 17, 2020
1 parent 6b6bafb commit b456664
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 4 additions & 3 deletions hs-abci-sdk/src/Tendermint/SDK/Application/Handlers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import Control.Lens (from, to, (&), (.~),
(^.))
import Crypto.Hash (Digest)
import Crypto.Hash.Algorithms (SHA256)
import qualified Data.Aeson as A
import qualified Data.ByteArray.Base64String as Base64
import Data.Default.Class (Default (..))
import Data.Proxy
import Data.Text
import Data.String.Conversions (cs)
import Network.ABCI.Server.App (App (..),
MessageType (..),
Request (..),
Expand Down Expand Up @@ -179,7 +180,7 @@ makeHandlers (HandlersContext{..} :: HandlersContext alg ms core) =
Right bbr ->
return . ResponseBeginBlock $ bbr
Left e ->
return . ResponseException . Resp.Exception . pack $ "Fatal Error in handling of BeginBlock: " ++ show e
return . ResponseException . Resp.Exception . cs . A.encode $ e

endBlock :: Handler 'MTEndBlock (BA.BaseAppEffs core)
endBlock (RequestEndBlock eb) = do
Expand All @@ -188,7 +189,7 @@ makeHandlers (HandlersContext{..} :: HandlersContext alg ms core) =
Right ebr ->
return . ResponseEndBlock $ ebr
Left e ->
return . ResponseException . Resp.Exception . pack $ "Fatal Error in handling of EndBlock: " ++ show e
return . ResponseException . Resp.Exception . cs . A.encode $ e



Expand Down
11 changes: 10 additions & 1 deletion hs-abci-sdk/src/Tendermint/SDK/BaseApp/Errors.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ module Tendermint.SDK.BaseApp.Errors

import Control.Exception (Exception)
import Control.Lens (Lens', lens)
import qualified Data.Aeson as A
import Data.String.Conversions (cs)
import Data.Text (Text, intercalate)
import Data.Word (Word32, Word64)
import GHC.Generics (Generic)
import Network.ABCI.Types.Messages.Common (defaultABCIOptions)
import qualified Network.ABCI.Types.Messages.Response as Response
import Polysemy
import Polysemy.Error (Error, throw)
Expand All @@ -24,10 +27,16 @@ data AppError = AppError
{ appErrorCode :: Word32
, appErrorCodespace :: Text
, appErrorMessage :: Text
} deriving (Eq, Show)
} deriving (Eq, Show, Generic)

instance Exception AppError

instance A.ToJSON AppError where
toJSON = A.genericToJSON $ defaultABCIOptions "appError"

instance A.FromJSON AppError where
parseJSON = A.genericParseJSON $ defaultABCIOptions "appError"

-- | Allows for custom application error types to be coerced into the
-- standard error resposne.
class IsAppError e where
Expand Down

0 comments on commit b456664

Please sign in to comment.