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 ...@@ -51,3 +51,14 @@ errorsViewCpt = here.component "errorsView" cpt
Nothing -> es Nothing -> es
Just es' -> es' Just es' -> es'
) errors ) 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 ...@@ -4,21 +4,55 @@ import Gargantext.Prelude
import Data.Array as A import Data.Array as A
import Data.Either (Either(..)) import Data.Either (Either(..))
import Data.Maybe (Maybe(..))
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Gargantext.Config.REST (RESTError) import Gargantext.Config.REST (RESTError)
import Gargantext.Types (FrontendError(..)) import Gargantext.Types (AsyncProgress(..), AsyncTaskEvent(..), AsyncTaskLog(..), FrontendError(..))
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Toestand as T import Toestand as T
here :: R2.Here here :: R2.Here
here = R2.here "Gargantext.Config.Utils" here = R2.here "Gargantext.Config.Utils"
handleRESTError :: forall a. T.Box (Array FrontendError) handleRESTError :: forall a.
T.Box (Array FrontendError)
-> Either RESTError a -> Either RESTError a
-> (a -> Aff Unit) -> (a -> Aff Unit)
-> Aff Unit -> Aff Unit
handleRESTError errors (Left error) _ = liftEffect $ do handleRESTError errors (Left error) _ = liftEffect $ do
T.modify_ (A.cons $ FRESTError { error }) errors T.modify_ (A.cons $ FRESTError { error }) errors
here.log2 "[handleTaskError] RESTError" error 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 _ ...@@ -740,8 +740,15 @@ derive instance Generic AsyncProgress _
derive instance Newtype AsyncProgress _ derive instance Newtype AsyncProgress _
derive newtype instance JSON.ReadForeign 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 { newtype AsyncTaskLog = AsyncTaskLog {
events :: Array String events :: Array AsyncTaskEvent
, failed :: Int , failed :: Int
, remaining :: Int , remaining :: Int
, succeeded :: Int , succeeded :: Int
...@@ -781,10 +788,10 @@ toggleSidePanelState Opened = Closed ...@@ -781,10 +788,10 @@ toggleSidePanelState Opened = Closed
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
data FrontendError = FStringError data FrontendError =
{ error :: String FStringError { error :: String }
} | FRESTError | FRESTError { error :: RESTError }
{ error :: RESTError } | FOtherError { error :: String }
derive instance Generic FrontendError _ derive instance Generic FrontendError _
instance Eq FrontendError where eq = genericEq 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