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
2730e32c
Commit
2730e32c
authored
Nov 06, 2023
by
Alfredo Di Napoli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Job errors -> frontend error
parent
b313927a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
129 additions
and
7 deletions
+129
-7
Errors.hs
src/Gargantext/API/Errors.hs
+16
-7
Types.hs
src/Gargantext/API/Errors/Types.hs
+107
-0
Backend.hs
src/Gargantext/API/Errors/Types/Backend.hs
+6
-0
No files found.
src/Gargantext/API/Errors.hs
View file @
2730e32c
...
...
@@ -16,17 +16,19 @@ module Gargantext.API.Errors (
import
Prelude
import
Control.Exception
import
Data.Validity
(
prettyValidation
)
import
Gargantext.API.Admin.Auth.Types
import
Gargantext.API.Errors.Class
as
Class
import
Gargantext.API.Errors.Types
as
Types
import
Gargantext.API.Errors.TH
(
deriveHttpStatusCode
)
import
Gargantext.API.Errors.Types
as
Types
import
Gargantext.Database.Query.Table.Node.Error
hiding
(
nodeError
)
import
Gargantext.Database.Query.Tree
hiding
(
treeError
)
import
Gargantext.Utils.Jobs.Monad
(
JobError
(
..
))
import
Servant.Server
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
)
import
Gargantext.API.Admin.Auth.Types
import
qualified
Network.HTTP.Types.Status
as
HTTP
$
(
deriveHttpStatusCode
''
B
ackendErrorCode
)
...
...
@@ -48,9 +50,16 @@ backendErrorToFrontendError = \case
->
authErrorToFrontendError
authError
InternalServerError
_internalServerError
->
undefined
InternalJobError
_
jobError
->
undefined
InternalJobError
jobError
->
jobErrorToFrontendError
jobError
jobErrorToFrontendError
::
JobError
->
FrontendError
jobErrorToFrontendError
=
\
case
InvalidIDType
idTy
->
mkFrontendErrNoDiagnostic
$
FE_job_error_invalid_id_type
idTy
IDExpired
jobId
->
mkFrontendErrNoDiagnostic
$
FE_job_error_expired
jobId
InvalidMacID
macId
->
mkFrontendErrNoDiagnostic
$
FE_job_error_invalid_mac
macId
UnknownJob
jobId
->
mkFrontendErrNoDiagnostic
$
FE_job_error_unknown_job
jobId
JobException
err
->
mkFrontendErrNoDiagnostic
$
FE_job_error_generic_exception
(
T
.
pack
$
displayException
err
)
authErrorToFrontendError
::
AuthenticationError
->
FrontendError
authErrorToFrontendError
=
\
case
...
...
src/Gargantext/API/Errors/Types.hs
View file @
2730e32c
...
...
@@ -226,6 +226,30 @@ data instance ToFrontendErrorData 'EC_500__tree_error_too_many_roots =
FE_tree_error_too_many_roots
{
tmr_roots
::
NonEmpty
NodeId
}
deriving
(
Show
,
Eq
,
Generic
)
--
-- Job errors
--
data
instance
ToFrontendErrorData
'E
C
_500__job_error_invalid_id_type
=
FE_job_error_invalid_id_type
{
jeiit_type
::
T
.
Text
}
deriving
(
Show
,
Eq
,
Generic
)
data
instance
ToFrontendErrorData
'E
C
_500__job_error_expired
=
FE_job_error_expired
{
jee_job_id
::
Int
}
deriving
(
Show
,
Eq
,
Generic
)
data
instance
ToFrontendErrorData
'E
C
_500__job_error_invalid_mac
=
FE_job_error_invalid_mac
{
jeim_mac
::
T
.
Text
}
deriving
(
Show
,
Eq
,
Generic
)
data
instance
ToFrontendErrorData
'E
C
_500__job_error_unknown_job
=
FE_job_error_unknown_job
{
jeuj_job_id
::
Int
}
deriving
(
Show
,
Eq
,
Generic
)
data
instance
ToFrontendErrorData
'E
C
_500__job_error_generic_exception
=
FE_job_error_generic_exception
{
jege_error
::
T
.
Text
}
deriving
(
Show
,
Eq
,
Generic
)
----------------------------------------------------------------------------
-- JSON instances. It's important to have nice and human readable instances.
-- It's also important that they all roundtrips, i.e. that given a 'ToFrontendErrorData'
...
...
@@ -317,6 +341,55 @@ instance FromJSON (ToFrontendErrorData 'EC_500__tree_error_too_many_roots) where
tmr_roots
<-
o
.:
"node_ids"
pure
FE_tree_error_too_many_roots
{
..
}
--
-- job errors
--
instance
ToJSON
(
ToFrontendErrorData
'E
C
_500__job_error_invalid_id_type
)
where
toJSON
(
FE_job_error_invalid_id_type
idTy
)
=
object
[
"type"
.=
toJSON
idTy
]
instance
FromJSON
(
ToFrontendErrorData
'E
C
_500__job_error_invalid_id_type
)
where
parseJSON
=
withObject
"FE_job_error_invalid_id_type"
$
\
o
->
do
jeiit_type
<-
o
.:
"type"
pure
FE_job_error_invalid_id_type
{
..
}
instance
ToJSON
(
ToFrontendErrorData
'E
C
_500__job_error_expired
)
where
toJSON
(
FE_job_error_expired
jobId
)
=
object
[
"job_id"
.=
toJSON
jobId
]
instance
FromJSON
(
ToFrontendErrorData
'E
C
_500__job_error_expired
)
where
parseJSON
=
withObject
"FE_job_error_expired"
$
\
o
->
do
jee_job_id
<-
o
.:
"job_id"
pure
FE_job_error_expired
{
..
}
instance
ToJSON
(
ToFrontendErrorData
'E
C
_500__job_error_invalid_mac
)
where
toJSON
(
FE_job_error_invalid_mac
mac
)
=
object
[
"mac"
.=
toJSON
mac
]
instance
FromJSON
(
ToFrontendErrorData
'E
C
_500__job_error_invalid_mac
)
where
parseJSON
=
withObject
"FE_job_error_invalid_mac"
$
\
o
->
do
jeim_mac
<-
o
.:
"mac"
pure
FE_job_error_invalid_mac
{
..
}
instance
ToJSON
(
ToFrontendErrorData
'E
C
_500__job_error_unknown_job
)
where
toJSON
(
FE_job_error_unknown_job
jobId
)
=
object
[
"job_id"
.=
toJSON
jobId
]
instance
FromJSON
(
ToFrontendErrorData
'E
C
_500__job_error_unknown_job
)
where
parseJSON
=
withObject
"FE_job_error_unknown_job"
$
\
o
->
do
jeuj_job_id
<-
o
.:
"job_id"
pure
FE_job_error_unknown_job
{
..
}
instance
ToJSON
(
ToFrontendErrorData
'E
C
_500__job_error_generic_exception
)
where
toJSON
(
FE_job_error_generic_exception
err
)
=
object
[
"error"
.=
toJSON
err
]
instance
FromJSON
(
ToFrontendErrorData
'E
C
_500__job_error_generic_exception
)
where
parseJSON
=
withObject
"FE_job_error_generic_exception"
$
\
o
->
do
jege_error
<-
o
.:
"error"
pure
FE_job_error_generic_exception
{
..
}
----------------------------------------------------------------------------
-- Arbitrary instances and test data generation
----------------------------------------------------------------------------
...
...
@@ -363,6 +436,23 @@ genFrontendErr be = do
->
do
nodes
<-
arbitrary
pure
$
mkFrontendErr'
txt
$
FE_tree_error_too_many_roots
nodes
-- job errors
EC_500__job_error_invalid_id_type
->
do
idTy
<-
arbitrary
pure
$
mkFrontendErr'
txt
$
FE_job_error_invalid_id_type
idTy
EC_500__job_error_expired
->
do
jobId
<-
getPositive
<$>
arbitrary
pure
$
mkFrontendErr'
txt
$
FE_job_error_expired
jobId
EC_500__job_error_invalid_mac
->
do
macId
<-
arbitrary
pure
$
mkFrontendErr'
txt
$
FE_job_error_expired
macId
EC_500__job_error_unknown_job
->
do
jobId
<-
getPositive
<$>
arbitrary
pure
$
mkFrontendErr'
txt
$
FE_job_error_unknown_job
jobId
EC_500__job_error_generic_exception
->
do
err
<-
arbitrary
pure
$
mkFrontendErr'
txt
$
FE_job_error_generic_exception
err
instance
ToJSON
BackendErrorCode
where
toJSON
=
JSON
.
String
.
T
.
pack
.
drop
3
.
show
...
...
@@ -420,3 +510,20 @@ instance FromJSON FrontendError where
EC_500__tree_error_too_many_roots
->
do
(
fe_data
::
ToFrontendErrorData
'E
C
_500__tree_error_too_many_roots
)
<-
o
.:
"data"
pure
FrontendError
{
..
}
-- job errors
EC_500__job_error_invalid_id_type
->
do
(
fe_data
::
ToFrontendErrorData
'E
C
_500__job_error_invalid_id_type
)
<-
o
.:
"data"
pure
FrontendError
{
..
}
EC_500__job_error_expired
->
do
(
fe_data
::
ToFrontendErrorData
'E
C
_500__job_error_expired
)
<-
o
.:
"data"
pure
FrontendError
{
..
}
EC_500__job_error_invalid_mac
->
do
(
fe_data
::
ToFrontendErrorData
'E
C
_500__job_error_invalid_mac
)
<-
o
.:
"data"
pure
FrontendError
{
..
}
EC_500__job_error_unknown_job
->
do
(
fe_data
::
ToFrontendErrorData
'E
C
_500__job_error_unknown_job
)
<-
o
.:
"data"
pure
FrontendError
{
..
}
EC_500__job_error_generic_exception
->
do
(
fe_data
::
ToFrontendErrorData
'E
C
_500__job_error_generic_exception
)
<-
o
.:
"data"
pure
FrontendError
{
..
}
src/Gargantext/API/Errors/Types/Backend.hs
View file @
2730e32c
...
...
@@ -29,6 +29,12 @@ data BackendErrorCode
|
EC_404__tree_error_root_not_found
|
EC_404__tree_error_empty_root
|
EC_500__tree_error_too_many_roots
-- job errors
|
EC_500__job_error_invalid_id_type
|
EC_500__job_error_expired
|
EC_500__job_error_invalid_mac
|
EC_500__job_error_unknown_job
|
EC_500__job_error_generic_exception
deriving
(
Show
,
Read
,
Eq
,
Enum
,
Bounded
)
$
(
genSingletons
[
''
B
ackendErrorCode
])
...
...
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