Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hikaru
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
hikaru
Commits
27ad7d94
Verified
Commit
27ad7d94
authored
6 years ago
by
jan.hamal.dvorak
Browse files
Options
Downloads
Patches
Plain Diff
Keep just one throwError function
Signed-off-by:
Jan Hamal Dvořák
<
mordae@anilinux.org
>
parent
78b581fe
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/Web/Hikaru/Action.hs
+8
-19
8 additions, 19 deletions
lib/Web/Hikaru/Action.hs
with
8 additions
and
19 deletions
lib/Web/Hikaru/Action.hs
+
8
−
19
View file @
27ad7d94
...
...
@@ -63,7 +63,6 @@ module Web.Hikaru.Action
-- ** Errors
,
throwError
,
throwErrorMsg
-- ** Finalizing
,
registerFinalizer
...
...
@@ -482,7 +481,7 @@ where
if
matchMediaList
ctype
[
"application/json"
,
"text/json"
]
then
return
()
else
throwError
Msg
UnsupportedMediaType
"Send some JSON!"
else
throwError
UnsupportedMediaType
"Send some JSON!"
-- Taint and read.
setActionField
aeBody
BodyTainted
...
...
@@ -490,7 +489,7 @@ where
-- Try to parse.
value
<-
case
eitherDecode'
body
of
Left
reason
->
throwError
Msg
BadRequest
(
cs
reason
)
Left
reason
->
throwError
BadRequest
(
cs
reason
)
Right
value
->
return
value
-- Cache and return.
...
...
@@ -500,7 +499,7 @@ where
-- Now this is bad. We have already read the body,
-- but not as a JSON. This is an internal error.
_else
->
do
throwError
Msg
InternalError
"Body has been parsed as a non-JSON."
throwError
InternalError
"Body has been parsed as a non-JSON."
-- |
...
...
@@ -549,7 +548,7 @@ where
getChunk
<-
getBodyChunkIO
case
bodyType
of
Nothing
->
throwError
Msg
UnsupportedMediaType
"Send some form!"
Nothing
->
throwError
UnsupportedMediaType
"Send some form!"
Just
bt
->
do
-- Prepare for uploaded files finalization.
rtis
<-
createInternalState
...
...
@@ -566,7 +565,7 @@ where
-- Now this is bad. We have already read the body,
-- but not as a form. This is an internal error.
_else
->
do
throwError
Msg
InternalError
"Body has been parsed as a non-form."
throwError
InternalError
"Body has been parsed as a non-form."
-- |
...
...
@@ -602,7 +601,7 @@ where
-- Now this is bad. We have already read the body,
-- but not as a raw data. This is an internal error.
_else
->
do
throwError
Msg
InternalError
"Body has already been parsed."
throwError
InternalError
"Body has already been parsed."
-- Building Response -------------------------------------------------------
...
...
@@ -792,21 +791,11 @@ where
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.
--
throwError
Msg
::
(
MonadAction
m
)
=>
RequestError
->
Text
->
m
a
throwError
Msg
exn
msg
=
liftIO
$
throwIO
(
exn
,
msg
)
throwError
::
(
MonadAction
m
)
=>
RequestError
->
Text
->
m
a
throwError
exn
msg
=
liftIO
$
throwIO
(
exn
,
msg
)
-- Finalizing --------------------------------------------------------------
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment