Commit d88a5554 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 a74ea59d
Pipeline #7073 failed with stages
in 39 minutes and 9 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
......@@ -32,7 +32,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
import Gargantext.Prelude (Bool, Maybe)
import Gargantext.Prelude (Bool)
import Servant
--------------------------------------------------
......@@ -68,7 +68,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