Skip to content
Snippets Groups Projects
Verified Commit 27ad7d94 authored by jan.hamal.dvorak's avatar jan.hamal.dvorak
Browse files

Keep just one throwError function

parent 78b581fe
No related branches found
No related tags found
No related merge requests found
...@@ -63,7 +63,6 @@ module Web.Hikaru.Action ...@@ -63,7 +63,6 @@ module Web.Hikaru.Action
-- ** Errors -- ** Errors
, throwError , throwError
, throwErrorMsg
-- ** Finalizing -- ** Finalizing
, registerFinalizer , registerFinalizer
...@@ -482,7 +481,7 @@ where ...@@ -482,7 +481,7 @@ where
if matchMediaList ctype [ "application/json", "text/json" ] if matchMediaList ctype [ "application/json", "text/json" ]
then return () then return ()
else throwErrorMsg UnsupportedMediaType "Send some JSON!" else throwError UnsupportedMediaType "Send some JSON!"
-- Taint and read. -- Taint and read.
setActionField aeBody BodyTainted setActionField aeBody BodyTainted
...@@ -490,7 +489,7 @@ where ...@@ -490,7 +489,7 @@ where
-- Try to parse. -- Try to parse.
value <- case eitherDecode' body of value <- case eitherDecode' body of
Left reason -> throwErrorMsg BadRequest (cs reason) Left reason -> throwError BadRequest (cs reason)
Right value -> return value Right value -> return value
-- Cache and return. -- Cache and return.
...@@ -500,7 +499,7 @@ where ...@@ -500,7 +499,7 @@ where
-- Now this is bad. We have already read the body, -- Now this is bad. We have already read the body,
-- but not as a JSON. This is an internal error. -- but not as a JSON. This is an internal error.
_else -> do _else -> do
throwErrorMsg InternalError "Body has been parsed as a non-JSON." throwError InternalError "Body has been parsed as a non-JSON."
-- | -- |
...@@ -549,7 +548,7 @@ where ...@@ -549,7 +548,7 @@ where
getChunk <- getBodyChunkIO getChunk <- getBodyChunkIO
case bodyType of case bodyType of
Nothing -> throwErrorMsg UnsupportedMediaType "Send some form!" Nothing -> throwError UnsupportedMediaType "Send some form!"
Just bt -> do Just bt -> do
-- Prepare for uploaded files finalization. -- Prepare for uploaded files finalization.
rtis <- createInternalState rtis <- createInternalState
...@@ -566,7 +565,7 @@ where ...@@ -566,7 +565,7 @@ where
-- Now this is bad. We have already read the body, -- Now this is bad. We have already read the body,
-- but not as a form. This is an internal error. -- but not as a form. This is an internal error.
_else -> do _else -> do
throwErrorMsg InternalError "Body has been parsed as a non-form." throwError InternalError "Body has been parsed as a non-form."
-- | -- |
...@@ -602,7 +601,7 @@ where ...@@ -602,7 +601,7 @@ where
-- Now this is bad. We have already read the body, -- Now this is bad. We have already read the body,
-- but not as a raw data. This is an internal error. -- but not as a raw data. This is an internal error.
_else -> do _else -> do
throwErrorMsg InternalError "Body has already been parsed." throwError InternalError "Body has already been parsed."
-- Building Response ------------------------------------------------------- -- Building Response -------------------------------------------------------
...@@ -792,21 +791,11 @@ where ...@@ -792,21 +791,11 @@ where
setActionField aeRespMaker \_st _hs -> responseRaw comm resp setActionField aeRespMaker \_st _hs -> responseRaw comm resp
-- |
-- Throw error and hope someone catches it.
--
-- Actually, dispatcher checks for these and uses the registered
-- handlers to serve up customizable error pages.
--
throwError :: (MonadAction m) => (RequestError, Text) -> m a
throwError = liftIO . throwIO
-- | -- |
-- Same as 'throwError', but with a message. -- Same as 'throwError', but with a message.
-- --
throwErrorMsg :: (MonadAction m) => RequestError -> Text -> m a throwError :: (MonadAction m) => RequestError -> Text -> m a
throwErrorMsg exn msg = liftIO $ throwIO (exn, msg) throwError exn msg = liftIO $ throwIO (exn, msg)
-- Finalizing -------------------------------------------------------------- -- Finalizing --------------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment