Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
195
Issues
195
List
Board
Labels
Milestones
Merge Requests
12
Merge Requests
12
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
haskell-gargantext
Commits
2d2b4cba
Verified
Commit
2d2b4cba
authored
May 29, 2023
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[api] implement JSON errors
parent
833af93d
Pipeline
#4081
failed with stages
in 11 minutes and 45 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
12 deletions
+32
-12
Server.hs
src/Gargantext/API/Server.hs
+19
-7
Node.hs
src/Gargantext/Database/Query/Table/Node.hs
+1
-1
Error.hs
src/Gargantext/Database/Query/Table/Node/Error.hs
+12
-4
No files found.
src/Gargantext/API/Server.hs
View file @
2d2b4cba
...
@@ -17,7 +17,8 @@ module Gargantext.API.Server where
...
@@ -17,7 +17,8 @@ module Gargantext.API.Server where
import
Control.Lens
((
^.
))
import
Control.Lens
((
^.
))
import
Control.Monad.Except
(
withExceptT
)
import
Control.Monad.Except
(
withExceptT
)
import
Control.Monad.Reader
(
runReaderT
)
import
Control.Monad.Reader
(
runReaderT
)
import
Data.Text
(
Text
)
import
qualified
Data.Aeson
as
Aeson
import
Data.Text
(
Text
,
pack
)
import
Data.Version
(
showVersion
)
import
Data.Version
(
showVersion
)
import
Servant
import
Servant
import
Servant.Swagger.UI
(
swaggerSchemaUIServer
)
import
Servant.Swagger.UI
(
swaggerSchemaUIServer
)
...
@@ -63,24 +64,35 @@ server env = do
...
@@ -63,24 +64,35 @@ server env = do
:<|>
hoistServerWithContext
:<|>
hoistServerWithContext
(
Proxy
::
Proxy
GargAPI
)
(
Proxy
::
Proxy
GargAPI
)
(
Proxy
::
Proxy
AuthContext
)
(
Proxy
::
Proxy
AuthContext
)
transform
transform
JSON
(
serverGargAPI
(
env
^.
hasConfig
.
gc_url_backend_api
))
(
serverGargAPI
(
env
^.
hasConfig
.
gc_url_backend_api
))
:<|>
hoistServerWithContext
:<|>
hoistServerWithContext
(
Proxy
::
Proxy
GraphQL
.
API
)
(
Proxy
::
Proxy
GraphQL
.
API
)
(
Proxy
::
Proxy
AuthContext
)
(
Proxy
::
Proxy
AuthContext
)
transform
transform
JSON
GraphQL
.
api
GraphQL
.
api
:<|>
frontEndServer
:<|>
frontEndServer
where
where
transform
::
forall
a
.
GargM
Env
GargError
a
->
Handler
a
-- transform :: forall a. GargM Env GargError a -> Handler a
transform
=
Handler
.
withExceptT
showAsServantErr
.
(`
runReaderT
`
env
)
-- transform = Handler . withExceptT showAsServantErr . (`runReaderT` env)
transformJSON
::
forall
a
.
GargM
Env
GargError
a
->
Handler
a
transformJSON
=
Handler
.
withExceptT
showAsServantJSONErr
.
(`
runReaderT
`
env
)
showAsServantErr
::
GargError
->
ServerError
showAsServantErr
::
GargError
->
ServerError
showAsServantErr
(
GargNodeError
err
@
NoListFound
)
=
err404
{
errBody
=
BL8
.
pack
$
show
err
}
showAsServantErr
(
GargNodeError
err
@
(
NoListFound
{})
)
=
err404
{
errBody
=
BL8
.
pack
$
show
err
}
showAsServantErr
(
GargNodeError
err
@
NoRootFound
)
=
err404
{
errBody
=
BL8
.
pack
$
show
err
}
showAsServantErr
(
GargNodeError
err
@
NoRootFound
)
=
err404
{
errBody
=
BL8
.
pack
$
show
err
}
showAsServantErr
(
GargNodeError
err
@
NoCorpusFound
)
=
err404
{
errBody
=
BL8
.
pack
$
show
err
}
showAsServantErr
(
GargNodeError
err
@
NoCorpusFound
)
=
err404
{
errBody
=
BL8
.
pack
$
show
err
}
showAsServantErr
(
GargNodeError
err
@
NoUserFound
)
=
err404
{
errBody
=
BL8
.
pack
$
show
err
}
showAsServantErr
(
GargNodeError
err
@
NoUserFound
)
=
err404
{
errBody
=
BL8
.
pack
$
show
err
}
showAsServantErr
(
GargNodeError
err
@
(
DoesNotExist
_
))
=
err404
{
errBody
=
BL8
.
pack
$
show
err
}
showAsServantErr
(
GargNodeError
err
@
(
DoesNotExist
{}
))
=
err404
{
errBody
=
BL8
.
pack
$
show
err
}
showAsServantErr
(
GargServerError
err
)
=
err
showAsServantErr
(
GargServerError
err
)
=
err
showAsServantErr
a
=
err500
{
errBody
=
BL8
.
pack
$
show
a
}
showAsServantErr
a
=
err500
{
errBody
=
BL8
.
pack
$
show
a
}
showAsServantJSONErr
::
GargError
->
ServerError
showAsServantJSONErr
(
GargNodeError
err
@
(
NoListFound
{}))
=
err404
{
errBody
=
Aeson
.
encode
err
}
showAsServantJSONErr
(
GargNodeError
err
@
NoRootFound
)
=
err404
{
errBody
=
Aeson
.
encode
err
}
showAsServantJSONErr
(
GargNodeError
err
@
NoCorpusFound
)
=
err404
{
errBody
=
Aeson
.
encode
err
}
showAsServantJSONErr
(
GargNodeError
err
@
NoUserFound
)
=
err404
{
errBody
=
Aeson
.
encode
err
}
showAsServantJSONErr
(
GargNodeError
err
@
(
DoesNotExist
{}))
=
err404
{
errBody
=
Aeson
.
encode
err
}
showAsServantJSONErr
(
GargServerError
err
)
=
err
showAsServantJSONErr
a
=
err500
{
errBody
=
Aeson
.
encode
$
Aeson
.
object
[
(
"error"
,
Aeson
.
String
$
pack
$
show
a
)
]
}
src/Gargantext/Database/Query/Table/Node.hs
View file @
2d2b4cba
...
@@ -419,7 +419,7 @@ getOrMkList pId uId =
...
@@ -419,7 +419,7 @@ getOrMkList pId uId =
-- | TODO remove defaultList
-- | TODO remove defaultList
defaultList
::
(
HasNodeError
err
,
HasDBid
NodeType
)
=>
CorpusId
->
Cmd
err
ListId
defaultList
::
(
HasNodeError
err
,
HasDBid
NodeType
)
=>
CorpusId
->
Cmd
err
ListId
defaultList
cId
=
defaultList
cId
=
maybe
(
nodeError
NoListFound
)
(
pure
.
view
node_id
)
.
headMay
=<<
getListsWithParentId
cId
maybe
(
nodeError
(
NoListFound
cId
)
)
(
pure
.
view
node_id
)
.
headMay
=<<
getListsWithParentId
cId
defaultListMaybe
::
(
HasNodeError
err
,
HasDBid
NodeType
)
=>
CorpusId
->
Cmd
err
(
Maybe
NodeId
)
defaultListMaybe
::
(
HasNodeError
err
,
HasDBid
NodeType
)
=>
CorpusId
->
Cmd
err
(
Maybe
NodeId
)
defaultListMaybe
cId
=
headMay
<$>
map
(
view
node_id
)
<$>
getListsWithParentId
cId
defaultListMaybe
cId
=
headMay
<$>
map
(
view
node_id
)
<$>
getListsWithParentId
cId
...
...
src/Gargantext/Database/Query/Table/Node/Error.hs
View file @
2d2b4cba
...
@@ -12,15 +12,16 @@ module Gargantext.Database.Query.Table.Node.Error where
...
@@ -12,15 +12,16 @@ module Gargantext.Database.Query.Table.Node.Error where
import
Control.Lens
(
Prism
'
,
(
#
),
(
^?
))
import
Control.Lens
(
Prism
'
,
(
#
),
(
^?
))
import
Control.Monad.Except
(
MonadError
(
..
))
import
Control.Monad.Except
(
MonadError
(
..
))
import
Data.Text
(
Text
)
import
Data.Aeson
import
Data.Text
(
Text
,
pack
)
import
Prelude
hiding
(
null
,
id
,
map
,
sum
)
import
Prelude
hiding
(
null
,
id
,
map
,
sum
)
import
Gargantext.Database.Admin.Types.Node
(
NodeId
)
import
Gargantext.Database.Admin.Types.Node
(
ListId
,
NodeId
(
..
)
)
import
Gargantext.Prelude
hiding
(
sum
,
head
)
import
Gargantext.Prelude
hiding
(
sum
,
head
)
------------------------------------------------------------------------
------------------------------------------------------------------------
data
NodeError
=
NoListFound
data
NodeError
=
NoListFound
{
listId
::
ListId
}
|
NoRootFound
|
NoRootFound
|
NoCorpusFound
|
NoCorpusFound
|
NoUserFound
|
NoUserFound
...
@@ -37,7 +38,7 @@ data NodeError = NoListFound
...
@@ -37,7 +38,7 @@ data NodeError = NoListFound
instance
Show
NodeError
instance
Show
NodeError
where
where
show
NoListFound
=
"No list found"
show
(
NoListFound
{})
=
"No list found"
show
NoRootFound
=
"No Root found"
show
NoRootFound
=
"No Root found"
show
NoCorpusFound
=
"No Corpus found"
show
NoCorpusFound
=
"No Corpus found"
show
NoUserFound
=
"No user found"
show
NoUserFound
=
"No user found"
...
@@ -53,6 +54,13 @@ instance Show NodeError
...
@@ -53,6 +54,13 @@ instance Show NodeError
show
NeedsConfiguration
=
"Needs configuration"
show
NeedsConfiguration
=
"Needs configuration"
show
(
NodeError
e
)
=
"NodeError: "
<>
cs
e
show
(
NodeError
e
)
=
"NodeError: "
<>
cs
e
instance
ToJSON
NodeError
where
toJSON
(
NoListFound
{
listId
=
NodeId
listId
})
=
object
[
(
"error"
,
"No list found"
)
,
(
"listId"
,
Number
$
fromIntegral
listId
)
]
toJSON
err
=
object
[
(
"error"
,
String
$
pack
$
show
err
)
]
class
HasNodeError
e
where
class
HasNodeError
e
where
_NodeError
::
Prism'
e
NodeError
_NodeError
::
Prism'
e
NodeError
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment