-
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 #1 from haskell-works/newhoggy/new-RenderedError-type
New RenderedError types
- Loading branch information
Showing
6 changed files
with
116 additions
and
15 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,18 +1,11 @@ | ||
{-# LANGUAGE DeriveGeneric #-} | ||
|
||
module HaskellWorks.Error.Types | ||
( GenericError(..), | ||
TimedOut(..), | ||
) where | ||
( -- * Error types | ||
GenericError(GenericError), | ||
RenderedError(RenderedError), | ||
TimedOut(TimedOut), | ||
|
||
import HaskellWorks.Prelude | ||
|
||
newtype GenericError = GenericError | ||
{ message :: Text | ||
} | ||
deriving (Generic, Eq, Show) | ||
-- * Type classes | ||
ToRenderedError(..), | ||
) where | ||
|
||
newtype TimedOut = TimedOut | ||
{ message :: Text | ||
} | ||
deriving (Generic, Eq, Show) | ||
import HaskellWorks.Error.Types.All |
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,14 @@ | ||
{-# LANGUAGE DuplicateRecordFields #-} | ||
{-# LANGUAGE TypeSynonymInstances #-} | ||
|
||
module HaskellWorks.Error.Types.All ( | ||
GenericError (..), | ||
RenderedError (..), | ||
TimedOut(..), | ||
|
||
ToRenderedError (..), | ||
) where | ||
|
||
import HaskellWorks.Error.Types.GenericError | ||
import HaskellWorks.Error.Types.RenderedError | ||
import HaskellWorks.Error.Types.TimedOut |
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,26 @@ | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE DuplicateRecordFields #-} | ||
{-# LANGUAGE TypeSynonymInstances #-} | ||
|
||
module HaskellWorks.Error.Types.GenericError ( | ||
GenericError (..), | ||
) where | ||
|
||
import Data.Aeson | ||
import Data.Generics.Product.Any | ||
import HaskellWorks.Error.Types.RenderedError | ||
import Lens.Micro | ||
|
||
import HaskellWorks.Prelude | ||
|
||
newtype GenericError = GenericError | ||
{ message :: Text | ||
} | ||
deriving (Eq, Generic, Show) | ||
|
||
instance ToRenderedError GenericError where | ||
toRenderedError e = | ||
RenderedError | ||
{ error = "GenericError" | ||
, payload = toJSON $ e ^. the @"message" | ||
} |
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,32 @@ | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE DuplicateRecordFields #-} | ||
{-# LANGUAGE TypeSynonymInstances #-} | ||
|
||
module HaskellWorks.Error.Types.RenderedError ( | ||
RenderedError (..), | ||
|
||
ToRenderedError (..), | ||
) where | ||
|
||
import Data.Aeson | ||
|
||
import HaskellWorks.Prelude | ||
|
||
data RenderedError = RenderedError | ||
{ error :: Text | ||
, payload :: Value | ||
} | ||
deriving (Eq, Generic, Show) | ||
|
||
instance ToJSON RenderedError where | ||
toJSON e = | ||
object | ||
[ "error" .= error e | ||
, "payload" .= payload e | ||
] | ||
|
||
class ToRenderedError a where | ||
toRenderedError :: a -> RenderedError | ||
|
||
instance ToRenderedError RenderedError where | ||
toRenderedError = id |
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,26 @@ | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE DuplicateRecordFields #-} | ||
{-# LANGUAGE TypeSynonymInstances #-} | ||
|
||
module HaskellWorks.Error.Types.TimedOut ( | ||
TimedOut (..), | ||
) where | ||
|
||
import Data.Aeson | ||
import Data.Generics.Product.Any | ||
import HaskellWorks.Error.Types.RenderedError | ||
import Lens.Micro | ||
|
||
import HaskellWorks.Prelude | ||
|
||
newtype TimedOut = TimedOut | ||
{ message :: Text | ||
} | ||
deriving (Eq, Generic, Show) | ||
|
||
instance ToRenderedError TimedOut where | ||
toRenderedError e = | ||
RenderedError | ||
{ error = "TimedOut" | ||
, payload = toJSON $ e ^. the @"message" | ||
} |