You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
safeJSONresponse :: (Aeson.FromJSON a) => Response -> InputStream ByteString - > IO (Either Error (Response, a))
safeJSONresponse resp i = runUnexceptionalIO $ runEitherT $ do
v <- fmapLT (\e -> handle e (fromException e)) $ fromIO $
parseFromStream Aeson.json' i
case Aeson.fromJSON v of
Aeson.Success a -> return (resp, a)
Aeson.Error _ -> throwT parseError
where
parseError = Error Unavailable (T.pack "JSON parse error")
handle _ (Just (ParseException _)) = parseError
handle e _ = Error Unavailable (T.pack $ "Exception: " ++ show e)
For something generic to go into the library, this would probably be simplified to use Maybe and only catch the parse error -- other exceptions would still go through.
The text was updated successfully, but these errors were encountered:
@afcowie my specific issue is that parse errors are exceptions with it (because parseFromStream can throw a ParseException separately from aeson returning Error)
I currently use:
For something generic to go into the library, this would probably be simplified to use
Maybe
and only catch the parse error -- other exceptions would still go through.The text was updated successfully, but these errors were encountered: