-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from haskell-works/newhoggy/define-JsonDecodeE…
…rror-and-YamlDecodeError Define `JsonDecodeError` and `YamlDecodeError`
- Loading branch information
Showing
4 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
module HaskellWorks.Error.Types ( | ||
GenericError (..), | ||
JsonDecodeError (..), | ||
TimedOut(..), | ||
YamlDecodeError (..) | ||
) where | ||
|
||
import HaskellWorks.Error.Types.GenericError | ||
import HaskellWorks.Error.Types.JsonDecodeError | ||
import HaskellWorks.Error.Types.TimedOut | ||
import HaskellWorks.Error.Types.YamlDecodeError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE DuplicateRecordFields #-} | ||
{-# LANGUAGE NoFieldSelectors #-} | ||
{-# LANGUAGE OverloadedRecordDot #-} | ||
|
||
module HaskellWorks.Error.Types.JsonDecodeError | ||
( JsonDecodeError(..) | ||
, newJsonDecodeError | ||
) where | ||
|
||
|
||
import Data.Aeson (ToJSON (..), Value, (.=)) | ||
import qualified Data.Aeson as J | ||
import GHC.Generics | ||
|
||
import HaskellWorks.Prelude | ||
import HaskellWorks.ToText | ||
|
||
data JsonDecodeError = | ||
JsonDecodeError | ||
{ message :: Text | ||
, bytestring :: Maybe ByteString | ||
, text :: Maybe Text | ||
, json :: Maybe Value | ||
} | ||
deriving (Eq, Generic, Show) | ||
|
||
newJsonDecodeError :: ToText a => a -> JsonDecodeError | ||
newJsonDecodeError message = | ||
JsonDecodeError | ||
{ message = toText message | ||
, bytestring = Nothing | ||
, text = Nothing | ||
, json = Nothing | ||
} | ||
|
||
instance ToJSON JsonDecodeError where | ||
toJSON e = | ||
J.object | ||
[ "error" .= id @Text "JsonDecodeError" | ||
, "message" .= e.message | ||
, "text" .= e.text | ||
, "json" .= e.json | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE DuplicateRecordFields #-} | ||
|
||
module HaskellWorks.Error.Types.YamlDecodeError | ||
( YamlDecodeError(..) | ||
) where | ||
|
||
|
||
import Data.Aeson (ToJSON (..), (.=)) | ||
import qualified Data.Aeson as J | ||
import GHC.Generics | ||
import HaskellWorks.Prelude | ||
newtype YamlDecodeError = | ||
YamlDecodeError | ||
{ message :: Text | ||
} | ||
deriving (Eq, Generic, Show) | ||
|
||
instance ToJSON YamlDecodeError where | ||
toJSON e = | ||
J.object | ||
[ "error" .= id @Text "YamlDecodeError" | ||
, "message" .= e.message | ||
] |