Commit 93834b1e authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[searx] searx work + better support for task errors

parent 7ec15fbf
......@@ -51,3 +51,14 @@ errorsViewCpt = here.component "errorsView" cpt
Nothing -> es
Just es' -> es'
) errors
showError errors i (FOtherError { error }) =
RB.alert { dismissible: true
, onClose
, variant: "danger" } [ H.text $ show error ]
where
onClose = do
here.log2 "click!" error
T.modify_ (\es -> case deleteAt i es of
Nothing -> es
Just es' -> es'
) errors
......@@ -4,21 +4,55 @@ import Gargantext.Prelude
import Data.Array as A
import Data.Either (Either(..))
import Data.Maybe (Maybe(..))
import Effect.Aff (Aff)
import Effect.Class (liftEffect)
import Gargantext.Config.REST (RESTError)
import Gargantext.Types (FrontendError(..))
import Gargantext.Types (AsyncProgress(..), AsyncTaskEvent(..), AsyncTaskLog(..), FrontendError(..))
import Gargantext.Utils.Reactix as R2
import Toestand as T
here :: R2.Here
here = R2.here "Gargantext.Config.Utils"
handleRESTError :: forall a. T.Box (Array FrontendError)
handleRESTError :: forall a.
T.Box (Array FrontendError)
-> Either RESTError a
-> (a -> Aff Unit)
-> Aff Unit
handleRESTError errors (Left error) _ = liftEffect $ do
T.modify_ (A.cons $ FRESTError { error }) errors
here.log2 "[handleTaskError] RESTError" error
handleRESTError _ (Right task) handler = handler task
handleRESTError _ (Right task) handler = do
handler task
handleTaskRESTError :: T.Box (Array FrontendError)
-> Either RESTError AsyncProgress
-> (AsyncProgress -> Aff Unit)
-> Aff Unit
handleTaskRESTError errors eTask handler = do
handleRESTError errors eTask $ \task -> do
handleAsyncTaskError :: AsyncProgress
-> T.Box (Array FrontendError)
-> Aff Unit
handleAsyncTaskError (AsyncProgress { log, status }) errors = do
case A.uncons log of
Nothing -> do
liftEffect $ here.log "[handleAsyncTaskError] log empty"
pure unit
Just { head: AsyncTaskLog { events, failed } } -> do
if failed == 0
then do
liftEffect $ here.log "[handleAsyncTaskError] failed = 0"
pure unit
else case A.uncons events of
Nothing -> do
liftEffect $ here.log "[handleAsyncTaskError] events empty"
pure unit
Just { head: AsyncTaskEvent { message, level } } -> liftEffect $ do
T.modify_ (A.cons $ FOtherError { error: "[" <> level <> "] " <> message }) errors
here.log2 "[handleAsyncTaskError] message" message
here.log2 "[handleAsyncTaskError] level" level
......@@ -740,8 +740,15 @@ derive instance Generic AsyncProgress _
derive instance Newtype AsyncProgress _
derive newtype instance JSON.ReadForeign AsyncProgress
newtype AsyncTaskEvent = AsyncTaskEvent
{ message :: String
, level :: String }
derive instance Generic AsyncTaskEvent _
derive instance Newtype AsyncTaskEvent _
derive newtype instance JSON.ReadForeign AsyncTaskEvent
newtype AsyncTaskLog = AsyncTaskLog {
events :: Array String
events :: Array AsyncTaskEvent
, failed :: Int
, remaining :: Int
, succeeded :: Int
......@@ -781,10 +788,10 @@ toggleSidePanelState Opened = Closed
---------------------------------------------------------------------------
data FrontendError = FStringError
{ error :: String
} | FRESTError
{ error :: RESTError }
data FrontendError =
FStringError { error :: String }
| FRESTError { error :: RESTError }
| FOtherError { error :: String }
derive instance Generic FrontendError _
instance Eq FrontendError where eq = genericEq
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