[errors] more error parsing

Handle case when "type" is not present in error. This shows up, for
example, in gql when a query is made without required parameters.
parent 764bd7fb
Pipeline #5557 failed with stage
in 0 seconds
...@@ -38,16 +38,18 @@ actionSearch :: R2.Component Props ...@@ -38,16 +38,18 @@ actionSearch :: R2.Component Props
actionSearch = R.createElement actionSearchCpt actionSearch = R.createElement actionSearchCpt
actionSearchCpt :: R.Component Props actionSearchCpt :: R.Component Props
actionSearchCpt = here.component "actionSearch" cpt where actionSearchCpt = here.component "actionSearch" cpt where
cpt props@({ session }) _ = do cpt props@({ boxes: { errors }, session }) _ = do
useLoader { errorHandler useLoader { errorHandler: errorHandler errors
, loader: loadLanguages , loader: loadLanguages
, path: { session } , path: { session }
, render: \langs -> , render: \langs ->
actionSearchWithLangs (Record.merge props { langs }) [] } actionSearchWithLangs (Record.merge props { langs }) [] }
where where
errorHandler err = case err of errorHandler errors error = do
ReadJSONError err' -> here.warn2 "[actionSearch] ReadJSONError" $ show err' T.modify_ (A.cons $ GT.FRESTError { error }) errors
_ -> here.warn2 "[actionSearch] RESTError" err case error of
ReadJSONError err' -> here.warn2 "[actionSearch] ReadJSONError" $ show err'
_ -> here.warn2 "[actionSearch] RESTError" error
type PropsWithLangs = type PropsWithLangs =
( langs :: Array Lang ( langs :: Array Lang
......
...@@ -41,16 +41,18 @@ actionWriteNodesDocuments :: R2.Component ActionWriteNodesDocuments ...@@ -41,16 +41,18 @@ actionWriteNodesDocuments :: R2.Component ActionWriteNodesDocuments
actionWriteNodesDocuments = R.createElement actionWriteNodesDocumentsCpt actionWriteNodesDocuments = R.createElement actionWriteNodesDocumentsCpt
actionWriteNodesDocumentsCpt :: R.Component ActionWriteNodesDocuments actionWriteNodesDocumentsCpt :: R.Component ActionWriteNodesDocuments
actionWriteNodesDocumentsCpt = here.component "actionWriteNodesDocuments" cpt where actionWriteNodesDocumentsCpt = here.component "actionWriteNodesDocuments" cpt where
cpt props@({ session }) _ = do cpt props@({ boxes: { errors }, session }) _ = do
useLoader { errorHandler useLoader { errorHandler: errorHandler errors
, loader: loadLanguages , loader: loadLanguages
, path: { session } , path: { session }
, render: \langs -> , render: \langs ->
actionWriteNodesDocumentsWithLangs (Record.merge props { langs }) [] } actionWriteNodesDocumentsWithLangs (Record.merge props { langs }) [] }
where where
errorHandler err = case err of errorHandler errors error = do
ReadJSONError err' -> here.warn2 "[actionSearch] ReadJSONError" $ show err' T.modify_ (A.cons $ GT.FRESTError { error }) errors
_ -> here.warn2 "[actionSearch] RESTError" err case error of
ReadJSONError err' -> here.warn2 "[actionWriteNodesDocuments] ReadJSONError" $ show err'
_ -> here.warn2 "[actionWriteNodesDocuments] RESTError" error
type ActionWriteNodesDocumentsWithLangs = type ActionWriteNodesDocumentsWithLangs =
( langs :: Array Lang ( langs :: Array Lang
......
...@@ -104,8 +104,13 @@ parseGQLJson json = ...@@ -104,8 +104,13 @@ parseGQLJson json =
Nothing -> REST.CustomError "[gqlQuery] empty 'graphQLErrors'" Nothing -> REST.CustomError "[gqlQuery] empty 'graphQLErrors'"
Just gqlErr -> case gqlErr .? "extensions" of Just gqlErr -> case gqlErr .? "extensions" of
Nothing -> REST.CustomError "[gqlQuery] graphQLError no 'extensions'" Nothing -> REST.CustomError "[gqlQuery] graphQLError no 'extensions'"
Just ext -> case (Foreign.unsafeToForeign >>> JSON.read >>> lmap toJsonError $ ext) of Just ext -> case (Foreign.unsafeToForeign >>> JSON.read $ ext) of
Left err' -> REST.CustomError $ "[gqlQuery] error reading 'extensions': " <> show err' Left _err -> do
-- OK so maybe we don't have "type" in error, try to parse the message only
case (Foreign.unsafeToForeign >>> JSON.read $ gqlErr :: Either Foreign.MultipleErrors { message :: String }) of
Left err' ->
REST.CustomError $ "[gqlQuery] don't know how to parse error: " <> show err'
Right { message } -> REST.CustomError message
Right err' -> REST.FE err' Right err' -> REST.FE err'
where where
decodeFn = Foreign.unsafeToForeign >>> JSON.read >>> lmap toJsonError decodeFn = Foreign.unsafeToForeign >>> JSON.read >>> lmap toJsonError
......
...@@ -171,7 +171,8 @@ instance JSON.ReadForeign FrontendError where ...@@ -171,7 +171,8 @@ instance JSON.ReadForeign FrontendError where
pure $ EC_500__node_generic_exception { error } pure $ EC_500__node_generic_exception { error }
"EC_500__node_not_implemented_yet" -> do "EC_500__node_not_implemented_yet" -> do
pure $ EC_500__node_not_implemented_yet pure $ EC_500__node_not_implemented_yet
_ -> Foreign.fail $ Foreign.ForeignError $ "deserialization for '" <> type_ <> "' not implemented" _ -> do
Foreign.fail $ Foreign.ForeignError $ "deserialization for '" <> type_ <> "' not implemented"
logRESTError :: R2.Here -> String -> RESTError -> Effect Unit logRESTError :: R2.Here -> String -> RESTError -> Effect Unit
logRESTError here' prefix e = here'.warn2 (prefix <> " " <> show e) e logRESTError here' prefix e = here'.warn2 (prefix <> " " <> show e) e
......
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