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
148
Issues
148
List
Board
Labels
Milestones
Merge Requests
7
Merge Requests
7
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
988c0f97
Commit
988c0f97
authored
Nov 06, 2023
by
Alfredo Di Napoli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support InternalValidationError
parent
75f7a690
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
3 deletions
+44
-3
Errors.hs
src/Gargantext/API/Errors.hs
+6
-2
Types.hs
src/Gargantext/API/Errors/Types.hs
+36
-1
Backend.hs
src/Gargantext/API/Errors/Types/Backend.hs
+2
-0
No files found.
src/Gargantext/API/Errors.hs
View file @
988c0f97
...
...
@@ -25,6 +25,7 @@ import qualified Data.Aeson as JSON
import
qualified
Network.HTTP.Types.Status
as
HTTP
import
qualified
Data.Text
as
T
import
Gargantext.Database.Query.Tree
hiding
(
treeError
)
import
Data.Validity
(
prettyValidation
)
$
(
deriveHttpStatusCode
''
B
ackendErrorCode
)
...
...
@@ -37,8 +38,11 @@ backendErrorToFrontendError = \case
->
nodeErrorToFrontendError
nodeError
InternalTreeError
treeError
->
treeErrorToFrontendError
treeError
InternalValidationError
_validationError
->
undefined
InternalValidationError
validationError
->
mkFrontendErr'
"A validation error occurred"
$
FE_validation_error
$
case
prettyValidation
validationError
of
Nothing
->
"unknown_validation_error"
Just
v
->
T
.
pack
v
InternalJoseError
_joseError
->
undefined
InternalServerError
_internalServerError
...
...
src/Gargantext/API/Errors/Types.hs
View file @
988c0f97
...
...
@@ -45,7 +45,7 @@ import Data.Aeson.Types (typeMismatch, emptyArray)
import
Data.Singletons.TH
import
Data.List.NonEmpty
(
NonEmpty
)
import
Data.Typeable
import
Data.Validity
(
Validation
)
import
Data.Validity
(
Validation
(
..
),
ValidationChain
(
..
),
prettyValidation
)
import
GHC.Generics
import
GHC.Stack
import
Gargantext.API.Errors.Class
...
...
@@ -67,6 +67,7 @@ import qualified Gargantext.Utils.Jobs.Monad as Jobs
import
qualified
Servant.Job.Types
as
SJ
import
Text.Read
(
readMaybe
)
import
qualified
Data.List.NonEmpty
as
NE
import
Data.Maybe
-- | A 'WithStacktrace' carries an error alongside its
-- 'CallStack', to be able to print the correct source location
...
...
@@ -190,6 +191,14 @@ data instance ToFrontendErrorData 'EC_404__node_error_not_found =
FE_node_error_not_found
{
nenf_node_id
::
!
NodeId
}
deriving
(
Show
,
Eq
,
Generic
)
--
-- validation errors
--
data
instance
ToFrontendErrorData
'E
C
_400__validation_error
=
FE_validation_error
{
validation_error
::
T
.
Text
}
deriving
(
Show
,
Eq
,
Generic
)
--
-- Tree errors
--
...
...
@@ -247,6 +256,22 @@ instance FromJSON (ToFrontendErrorData 'EC_404__node_error_not_found) where
nenf_node_id
<-
o
.:
"node_id"
pure
FE_node_error_not_found
{
..
}
--
-- validation errors
--
instance
ToJSON
(
ToFrontendErrorData
'E
C
_400__validation_error
)
where
toJSON
(
FE_validation_error
val
)
=
toJSON
val
instance
FromJSON
(
ToFrontendErrorData
'E
C
_400__validation_error
)
where
parseJSON
(
String
txt
)
=
pure
$
FE_validation_error
txt
parseJSON
ty
=
typeMismatch
"FE_validation_error"
ty
--
-- tree errors
--
instance
ToJSON
(
ToFrontendErrorData
'E
C
_404__tree_error_root_not_found
)
where
toJSON
_
=
JSON
.
Null
...
...
@@ -292,6 +317,11 @@ genFrontendErr be = do
EC_404__node_error_not_found
->
do
nodeId
<-
arbitrary
pure
$
mkFrontendErr'
txt
(
FE_node_error_not_found
nodeId
)
-- validation error
EC_400__validation_error
->
do
let
genValChain
=
oneof
[
Violated
<$>
arbitrary
,
Location
<$>
arbitrary
<*>
genValChain
]
chain
<-
listOf1
genValChain
pure
$
mkFrontendErr'
txt
$
FE_validation_error
(
T
.
pack
$
fromMaybe
"unknown_validation_error"
$
prettyValidation
$
Validation
chain
)
-- tree errors
EC_404__tree_error_root_not_found
...
...
@@ -339,6 +369,11 @@ instance FromJSON FrontendError where
(
fe_data
::
ToFrontendErrorData
'E
C
_500__node_error_not_implemented_yet
)
<-
o
.:
"data"
pure
FrontendError
{
..
}
-- validation error
EC_400__validation_error
->
do
(
fe_data
::
ToFrontendErrorData
'E
C
_400__validation_error
)
<-
o
.:
"data"
pure
FrontendError
{
..
}
-- tree errors
EC_404__tree_error_root_not_found
->
do
(
fe_data
::
ToFrontendErrorData
'E
C
_404__tree_error_root_not_found
)
<-
o
.:
"data"
...
...
src/Gargantext/API/Errors/Types/Backend.hs
View file @
988c0f97
...
...
@@ -21,6 +21,8 @@ data BackendErrorCode
|
EC_404__node_error_not_found
|
EC_404__node_error_corpus_not_found
|
EC_500__node_error_not_implemented_yet
-- validation errors
|
EC_400__validation_error
-- tree errors
|
EC_404__tree_error_root_not_found
|
EC_404__tree_error_empty_root
...
...
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