Skip to content

Commit 1accfb5

Browse files
authored
Merge pull request #1 from Cheshirrrrrr/develop
version 0.1.0.4: added JsonException
2 parents 75d8ff6 + d55b9f6 commit 1accfb5

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

src/Web/Template.hs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
module Web.Template
2-
( UserId, Port, Env, WebM, ScottyM
3-
, CustomWebServer (..), Process (..), Route (..)
4-
, runWebServer
5-
, JsonWebError (..)
2+
(
3+
module Web.Template.Except
4+
, module Web.Template.Server
65
) where
76

8-
import Web.Template.Except (JsonWebError (..))
9-
import Web.Template.Server (CustomWebServer (..), Env, Port,
10-
Process (..), Route (..), ScottyM, UserId,
11-
WebM, runWebServer)
7+
import Web.Template.Except
8+
import Web.Template.Server

src/Web/Template/Except.hs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
1-
{-# LANGUAGE DeriveGeneric #-}
1+
{-# LANGUAGE DeriveGeneric #-}
22

33
module Web.Template.Except
4-
( Except (..), JsonWebError (..)
4+
(
5+
Except (..)
6+
, JsonWebError (..)
7+
, ScottyError (..)
58
, handleEx
69
) where
710

8-
import Data.Aeson (ToJSON (..))
11+
import Data.Aeson (FromJSON (..), ToJSON (..))
912
import Data.String (fromString)
1013
import GHC.Generics (Generic)
11-
import Network.HTTP.Types.Status (status403, status404,
12-
status500)
14+
import Network.HTTP.Types.Status (status403, status404, status500)
1315
import Web.Scotty.Trans (ActionT, ScottyError (..), json,
1416
status)
1517

1618

1719
instance ScottyError Except where
18-
stringError = StringEx
20+
stringError = JsonException
1921
showError = fromString . show
2022

21-
data Except = Forbidden | NotFound Int | StringEx String
23+
data Except = Forbidden | NotFound Int | StringException String | JsonException String
2224
deriving (Show, Eq)
2325

2426
newtype JsonWebError = JsonWebError { error :: String }
2527
deriving (Generic)
2628

2729
instance ToJSON JsonWebError
30+
instance FromJSON JsonWebError
2831

2932
handleEx :: Monad m => Except -> ActionT Except m ()
3033
handleEx Forbidden = do
@@ -33,6 +36,9 @@ handleEx Forbidden = do
3336
handleEx (NotFound i) = do
3437
status status404
3538
json . JsonWebError $ "Can't find " ++ show i
36-
handleEx (StringEx str) = do
39+
handleEx (StringException str) = do
3740
status status500
3841
json . JsonWebError $ "Server problem: " ++ str
42+
handleEx (JsonException str) = do
43+
status status500
44+
json . JsonWebError $ str

web-template.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: web-template
2-
version: 0.1.0.3
2+
version: 0.1.0.4
33
synopsis: Web template
44
description:
55
Web template includes:

0 commit comments

Comments
 (0)