Commit b44e4c16 authored by Alfredo Di Napoli's avatar Alfredo Di Napoli

Add more cases to nodeErrorToFrontendError

parent 1573c5f3
...@@ -66,11 +66,11 @@ nodeErrorToFrontendError ne = case ne of ...@@ -66,11 +66,11 @@ nodeErrorToFrontendError ne = case ne of
NegativeId NegativeId
-> undefined -> undefined
NotImplYet NotImplYet
-> undefined -> mkFrontendErrShow FE_node_error_not_implemented_yet
ManyNodeUsers ManyNodeUsers
-> undefined -> undefined
DoesNotExist _nodeId DoesNotExist nodeId
-> undefined -> mkFrontendErrShow $ FE_node_error_not_found nodeId
NoContextFound _contextId NoContextFound _contextId
-> undefined -> undefined
NeedsConfiguration NeedsConfiguration
......
...@@ -180,12 +180,26 @@ data instance ToFrontendErrorData 'EC_404__node_error_corpus_not_found = ...@@ -180,12 +180,26 @@ data instance ToFrontendErrorData 'EC_404__node_error_corpus_not_found =
FE_node_error_corpus_not_found FE_node_error_corpus_not_found
deriving (Show, Eq, Generic) deriving (Show, Eq, Generic)
data instance ToFrontendErrorData 'EC_500__node_error_not_implemented_yet =
FE_node_error_not_implemented_yet
deriving (Show, Eq, Generic)
data instance ToFrontendErrorData 'EC_404__node_error_not_found =
FE_node_error_not_found { nenf_node_id :: !NodeId }
deriving (Show, Eq, Generic)
--
-- Tree errors
--
data instance ToFrontendErrorData 'EC_404__tree_error_root_not_found = data instance ToFrontendErrorData 'EC_404__tree_error_root_not_found =
RootNotFound { _rnf_rootId :: RootId } RootNotFound { _rnf_rootId :: RootId }
deriving (Show, Eq, Generic) deriving (Show, Eq, Generic)
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- JSON instances. It's important to have nice and human readable instances. -- 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'
-- payload, we can render it to JSON and parse it back.
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
instance ToJSON (ToFrontendErrorData 'EC_404__node_error_list_not_found) where instance ToJSON (ToFrontendErrorData 'EC_404__node_error_list_not_found) where
...@@ -209,6 +223,20 @@ instance ToJSON (ToFrontendErrorData 'EC_404__node_error_corpus_not_found) where ...@@ -209,6 +223,20 @@ instance ToJSON (ToFrontendErrorData 'EC_404__node_error_corpus_not_found) where
instance FromJSON (ToFrontendErrorData 'EC_404__node_error_corpus_not_found) where instance FromJSON (ToFrontendErrorData 'EC_404__node_error_corpus_not_found) where
parseJSON _ = pure FE_node_error_corpus_not_found parseJSON _ = pure FE_node_error_corpus_not_found
instance ToJSON (ToFrontendErrorData 'EC_500__node_error_not_implemented_yet) where
toJSON _ = JSON.Null
instance FromJSON (ToFrontendErrorData 'EC_500__node_error_not_implemented_yet) where
parseJSON _ = pure FE_node_error_not_implemented_yet
instance ToJSON (ToFrontendErrorData 'EC_404__node_error_not_found) where
toJSON (FE_node_error_not_found nodeId) = object [ "node_id" .= toJSON nodeId ]
instance FromJSON (ToFrontendErrorData 'EC_404__node_error_not_found) where
parseJSON = withObject "FE_node_error_not_found" $ \o -> do
nenf_node_id <- o .: "node_id"
pure FE_node_error_not_found{..}
instance ToJSON (ToFrontendErrorData 'EC_404__tree_error_root_not_found) where instance ToJSON (ToFrontendErrorData 'EC_404__tree_error_root_not_found) where
toJSON RootNotFound{..} = object [ "root_id" .= toJSON _rnf_rootId ] toJSON RootNotFound{..} = object [ "root_id" .= toJSON _rnf_rootId ]
...@@ -228,12 +256,21 @@ genFrontendErr :: BackendErrorCode -> Gen FrontendError ...@@ -228,12 +256,21 @@ genFrontendErr :: BackendErrorCode -> Gen FrontendError
genFrontendErr be = do genFrontendErr be = do
txt <- arbitrary txt <- arbitrary
case be of case be of
-- node errors
EC_404__node_error_list_not_found EC_404__node_error_list_not_found
-> arbitrary >>= \lid -> pure $ mkFrontendErr' txt $ FE_node_error_list_not_found lid -> arbitrary >>= \lid -> pure $ mkFrontendErr' txt $ FE_node_error_list_not_found lid
EC_404__node_error_root_not_found EC_404__node_error_root_not_found
-> pure $ mkFrontendErr' txt FE_node_error_root_not_found -> pure $ mkFrontendErr' txt FE_node_error_root_not_found
EC_404__node_error_corpus_not_found EC_404__node_error_corpus_not_found
-> pure $ mkFrontendErr' txt FE_node_error_corpus_not_found -> pure $ mkFrontendErr' txt FE_node_error_corpus_not_found
EC_500__node_error_not_implemented_yet
-> pure $ mkFrontendErr' txt FE_node_error_not_implemented_yet
EC_404__node_error_not_found
-> do nodeId <- arbitrary
pure $ mkFrontendErr' txt (FE_node_error_not_found nodeId)
-- tree errors
EC_404__tree_error_root_not_found EC_404__tree_error_root_not_found
-> do rootId <- arbitrary -> do rootId <- arbitrary
pure $ mkFrontendErr' txt (RootNotFound rootId) pure $ mkFrontendErr' txt (RootNotFound rootId)
...@@ -268,6 +305,14 @@ instance FromJSON FrontendError where ...@@ -268,6 +305,14 @@ instance FromJSON FrontendError where
EC_404__node_error_corpus_not_found -> do EC_404__node_error_corpus_not_found -> do
(fe_data :: ToFrontendErrorData 'EC_404__node_error_corpus_not_found) <- o .: "data" (fe_data :: ToFrontendErrorData 'EC_404__node_error_corpus_not_found) <- o .: "data"
pure FrontendError{..} pure FrontendError{..}
EC_404__node_error_not_found -> do
(fe_data :: ToFrontendErrorData 'EC_404__node_error_not_found) <- o .: "data"
pure FrontendError{..}
-- tree errors
EC_404__tree_error_root_not_found -> do EC_404__tree_error_root_not_found -> do
(fe_data :: ToFrontendErrorData 'EC_404__tree_error_root_not_found) <- o .: "data" (fe_data :: ToFrontendErrorData 'EC_404__tree_error_root_not_found) <- o .: "data"
pure FrontendError{..} pure FrontendError{..}
EC_500__node_error_not_implemented_yet -> do
(fe_data :: ToFrontendErrorData 'EC_500__node_error_not_implemented_yet) <- o .: "data"
pure FrontendError{..}
...@@ -18,7 +18,9 @@ data BackendErrorCode ...@@ -18,7 +18,9 @@ data BackendErrorCode
-- node errors -- node errors
EC_404__node_error_list_not_found EC_404__node_error_list_not_found
| EC_404__node_error_root_not_found | EC_404__node_error_root_not_found
| EC_404__node_error_not_found
| EC_404__node_error_corpus_not_found | EC_404__node_error_corpus_not_found
| EC_500__node_error_not_implemented_yet
-- tree errors -- tree errors
| EC_404__tree_error_root_not_found | EC_404__tree_error_root_not_found
deriving (Show, Read, Eq, Enum, Bounded) deriving (Show, Read, Eq, Enum, Bounded)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment