Commit 28e2927e authored by Grégoire Locqueville's avatar Grégoire Locqueville

Deal with error with a proper error

... instead of returning a `Maybe` to the frontend
parent 54675ae8
Pipeline #7097 passed with stages
in 59 minutes and 20 seconds
module Gargantext.API.Node.Corpus.Subcorpus where
import Data.Validity (Validation(..), ValidationChain(..))
import Gargantext.Prelude
import Gargantext.API.Errors.Types (BackendInternalError)
import Gargantext.API.Errors.Types (BackendInternalError(..))
import Gargantext.API.Routes.Named.Corpus (MakeSubcorpusAPI(..), SubcorpusParams(..))
import Gargantext.Core.NodeStory.Types (HasNodeStoryEnv)
import Gargantext.Core.NLP (HasNLPServer)
......@@ -21,12 +21,14 @@ makeSubcorpus :: ( HasNodeStoryEnv env
=> UserId
-> MakeSubcorpusAPI (AsServerT m)
makeSubcorpus user = MakeSubcorpusAPI $ \corpusId params -> do
case parseQuery (RawQuery $ _subcorpusParams_query params) of
Left _ -> return Nothing
Right q -> do
let queryText = _subcorpusParams_query params
case parseQuery (RawQuery queryText) of
Left msg -> throwError $ InternalValidationError $ Validation [Violated $
"Failed to parse the query " <> show queryText <> ": " <> msg]
Right q -> do
subcorpusId <- makeSubcorpusFromQuery
(UserDBId user)
corpusId
q
(_subcorpusParams_reuseParentList params)
return $ Just subcorpusId
return subcorpusId
......@@ -31,7 +31,7 @@ import Gargantext.API.Worker (WorkerAPI)
import Gargantext.Core.Text.Ngrams (NgramsType(..))
import Gargantext.Core.Utils.Prefix (unPrefix, unPrefixSwagger)
import Gargantext.Database.Admin.Types.Node (CorpusId, ListId, NodeId)
import Gargantext.Prelude (Bool, Maybe)
import Gargantext.Prelude (Bool)
import Servant
--------------------------------------------------
......@@ -67,7 +67,7 @@ newtype MakeSubcorpusAPI mode = MakeSubcorpusAPI
:> Capture "corpus_id" CorpusId
:> "subcorpus"
:> ReqBody '[JSON] SubcorpusParams
:> Post '[JSON] (Maybe NodeId) -- new subcorpus ID, if successful
:> Post '[JSON] NodeId -- new subcorpus ID
} deriving Generic
data SubcorpusParams = SubcorpusParams
......
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