Commit b313927a authored by Alfredo Di Napoli's avatar Alfredo Di Napoli

Improve internal JobError type

parent d0c5fec3
......@@ -29,6 +29,7 @@ import qualified Data.Text as T
import qualified Servant.Client as C
import qualified Servant.Job.Async as SJ
import qualified Servant.Job.Client as SJ
import qualified Servant.Job.Core as SJ
import qualified Servant.Job.Types as SJ
serveJobsAPI
......@@ -65,7 +66,7 @@ serveJobAPI t joberr jid' = wrap' (killJob t)
-> m a
wrap g = do
jid <- handleIDError joberr (checkJID jid')
job <- maybe (throwError $ joberr UnknownJob) pure =<< findJob jid
job <- maybe (throwError $ joberr $ UnknownJob (SJ._id_number jid)) pure =<< findJob jid
g jid job
wrap' g limit offset = wrap (g limit offset)
......
......@@ -112,10 +112,13 @@ findJob jid = do
liftIO $ lookupJob jid jmap
data JobError
= InvalidIDType
| IDExpired
=
-- | We expected to find a job tagged internall as \"job\", but we found the input @T.Text@ instead.
InvalidIDType T.Text
-- | The given ID expired.
| IDExpired Int
| InvalidMacID T.Text
| UnknownJob
| UnknownJob Int
| JobException SomeException
deriving Show
......@@ -126,8 +129,8 @@ checkJID
checkJID (SJ.PrivateID tn n t d) = do
now <- liftIO getCurrentTime
js <- getJobsSettings
if | tn /= "job" -> pure (Left InvalidIDType)
| now > addUTCTime (fromIntegral $ jsIDTimeout js) t -> pure (Left IDExpired)
if | tn /= "job" -> pure (Left $ InvalidIDType $ T.pack tn)
| now > addUTCTime (fromIntegral $ jsIDTimeout js) t -> pure (Left $ IDExpired n)
| d /= SJ.macID tn (jsSecretKey js) t n -> pure (Left $ InvalidMacID $ T.pack d)
| otherwise -> pure $ Right (SJ.PrivateID tn n t d)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment