Skip to content

Commit

Permalink
Merge pull request #11 from koterpillar/json-exception
Browse files Browse the repository at this point in the history
Handle JSON exceptions
  • Loading branch information
koterpillar authored Aug 15, 2017
2 parents 4a4387b + 3747c47 commit 7c068b9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Fetcher/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Control.Applicative
import Control.Exception.Lifted

import Network.HTTP.Client (HttpException)
import Network.HTTP.Simple (JSONException)

import Types.Config

Expand All @@ -19,8 +20,11 @@ logIOError context err = logErrorStr context (show err)
logHttpError :: (Alternative m, Show c) => c -> HttpException -> AppM (m a)
logHttpError context err = logErrorStr context (show err)

logJSONError :: (Alternative m, Show c) => c -> JSONException -> AppM (m a)
logJSONError context err = logErrorStr context (show err)

logErrors :: (Alternative m, Show c) => c -> AppM (m a) -> AppM (m a)
logErrors context = handle (logIOError context) . handle (logHttpError context)
logErrors context = handle (logIOError context) . handle (logHttpError context) . handle (logJSONError context)

logEither :: Alternative m => Either String a -> (a -> AppM (m b)) -> AppM (m b)
logEither (Left err) _ = logStr err >> return empty
Expand Down

0 comments on commit 7c068b9

Please sign in to comment.