[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
......@@ -38,16 +38,18 @@ actionSearch :: R2.Component Props
actionSearch = R.createElement actionSearchCpt
actionSearchCpt :: R.Component Props
actionSearchCpt = here.component "actionSearch" cpt where
cpt props@({ session }) _ = do
useLoader { errorHandler
cpt props@({ boxes: { errors }, session }) _ = do
useLoader { errorHandler: errorHandler errors
, loader: loadLanguages
, path: { session }
, render: \langs ->
actionSearchWithLangs (Record.merge props { langs }) [] }
where
errorHandler err = case err of
ReadJSONError err' -> here.warn2 "[actionSearch] ReadJSONError" $ show err'
_ -> here.warn2 "[actionSearch] RESTError" err
errorHandler errors error = do
T.modify_ (A.cons $ GT.FRESTError { error }) errors
case error of
ReadJSONError err' -> here.warn2 "[actionSearch] ReadJSONError" $ show err'
_ -> here.warn2 "[actionSearch] RESTError" error
type PropsWithLangs =
( langs :: Array Lang
......
......@@ -41,16 +41,18 @@ actionWriteNodesDocuments :: R2.Component ActionWriteNodesDocuments
actionWriteNodesDocuments = R.createElement actionWriteNodesDocumentsCpt
actionWriteNodesDocumentsCpt :: R.Component ActionWriteNodesDocuments
actionWriteNodesDocumentsCpt = here.component "actionWriteNodesDocuments" cpt where
cpt props@({ session }) _ = do
useLoader { errorHandler
cpt props@({ boxes: { errors }, session }) _ = do
useLoader { errorHandler: errorHandler errors
, loader: loadLanguages
, path: { session }
, render: \langs ->
actionWriteNodesDocumentsWithLangs (Record.merge props { langs }) [] }
where
errorHandler err = case err of
ReadJSONError err' -> here.warn2 "[actionSearch] ReadJSONError" $ show err'
_ -> here.warn2 "[actionSearch] RESTError" err
errorHandler errors error = do
T.modify_ (A.cons $ GT.FRESTError { error }) errors
case error of
ReadJSONError err' -> here.warn2 "[actionWriteNodesDocuments] ReadJSONError" $ show err'
_ -> here.warn2 "[actionWriteNodesDocuments] RESTError" error
type ActionWriteNodesDocumentsWithLangs =
( langs :: Array Lang
......
......@@ -104,8 +104,13 @@ parseGQLJson json =
Nothing -> REST.CustomError "[gqlQuery] empty 'graphQLErrors'"
Just gqlErr -> case gqlErr .? "extensions" of
Nothing -> REST.CustomError "[gqlQuery] graphQLError no 'extensions'"
Just ext -> case (Foreign.unsafeToForeign >>> JSON.read >>> lmap toJsonError $ ext) of
Left err' -> REST.CustomError $ "[gqlQuery] error reading 'extensions': " <> show err'
Just ext -> case (Foreign.unsafeToForeign >>> JSON.read $ ext) of
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'
where
decodeFn = Foreign.unsafeToForeign >>> JSON.read >>> lmap toJsonError
......
......@@ -171,7 +171,8 @@ instance JSON.ReadForeign FrontendError where
pure $ EC_500__node_generic_exception { error }
"EC_500__node_not_implemented_yet" -> do
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 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