如何在 Yesod 处理程序中“捕获”异常?

How can I `catch` an exception within a Yesod Handler?

当我尝试时:

foos <- (return $ map (encode .> cs .> jsonToFoo body) `catch` r400

我收到以下类型错误:

/path/to/File.hs:47:78: error:
    • Couldn't match type ‘(->) e0’ with ‘IO’
        arising from a functional dependency between:
          constraint ‘MonadBase IO ((->) e0)’ arising from a use of ‘r400’
          instance ‘MonadBase ((->) r) ((->) r)’ at <no location info>
    • In the second argument of ‘catch’, namely ‘r400’
      In a stmt of a 'do' block:
        foos <- (return $ map (encode .> cs .> jsonToFoo) body)
                `catch` r400
      In the expression:
        do { (body :: [Value]) <- requireJsonBody;
             foos <- (return $ map (encode .> cs .> jsonToFoo) body)
                     `catch` r400;
             .... }

如果有办法的话,涉及到liftIO,不是吗?

我只是错过了 catch 的参数:

foos <- (return $ map (encode .> cs .> jsonToFoo body)
  `catch` (\(e :: SomeException) -> r400)

太糟糕了,我从类型错误中看不出更明显。