]> Git — Sourcephile - gargantext.git/blob - src/Data/Gargantext/Error_hs
[FIX] Tree type and errors message in Date parsing.
[gargantext.git] / src / Data / Gargantext / Error_hs
1 module Data.Gargantext.Error where
2
3 import Control.Exception (Exception)
4 import Data.Typeable (Typeable)
5 import GHC.Generics (Generic)
6 import Network.HTTP.Client (HttpException)
7
8 import System.Exit (ExitCode (..), exitWith)
9 import System.IO (stderr)
10 --import Text.Parsec.Error
11 --import Text.Parsec.Pos hiding (Line)
12
13
14 data GargError = GargIOError String IOError
15 | GargHttpError String HttpException
16 | GargParseError String
17 | GargNgramsError String
18 | GargDatabaseError String
19 deriving (Show, Typeable, Generic)
20
21
22 instance Exception PandocError
23
24 -- | Handle GargError by exiting with an error message.
25 handleError :: Either GargError a -> IO a
26 handleError (Right r) = pure r
27 handleError (Left e) =
28 case e of
29 GargIOError _ err' -> ioError err'
30 GargHttpError u err' -> err 61 $
31 "Could not fetch " ++ u ++ "\n" ++ show err'
32 GargParseError s -> err 64 s
33 _ s -> err 0 s
34
35
36 err :: Int -> String -> IO a
37 err exitCode msg = do
38 UTF8.hPutStrLn stderr msg
39 exitWith $ ExitFailure exitCode
40 return undefined