Haskell 服务打印例外

Haskell 服务打印例外,haskell,servant,Haskell,Servant,如何打印所有异常的描述?最好切换调试/发布格式 标准Servant安装仅显示出500/出了问题,这并没有真正的帮助 HTTP/1.1 500 Internal Server Error Something went wrong Upd: 报告我的第一个处理程序时出现以下错误: Server.hs:152:31: error: • No instance for (MonadCatch ((:<|>) (Servant.Ha

如何打印所有异常的描述?最好切换调试/发布格式

标准Servant安装仅显示出
500/出了问题
,这并没有真正的帮助

HTTP/1.1 500 Internal Server Error

Something went wrong
Upd:

报告我的第一个处理程序时出现以下错误:

Server.hs:152:31: error:
    • No instance for (MonadCatch
                         ((:<|>) (Servant.Handler (Map.Map String String))))
        arising from a use of ‘catch’
    • In the expression:
        server `catch` (\ e -> handleExceptions (e :: SomeException))
      In an equation for ‘serverWithExceptionsHandled’:
          serverWithExceptionsHandled
            = server `catch` (\ e -> handleExceptions (e :: SomeException))
更新:

server :: Server API
server = ping
    :<|> signup
    :<|> singin
    :<|> account
    :<|> getSessions


serverWithExceptionsHandled = server `catch` (\e -> handleExceptions (e :: SomeException))

-- | print to console and then rethrow
handleExceptions :: (MonadIO m, MonadThrow m, Exception e) => e -> m b
handleExceptions e = do
  liftIO $ print e
  throwM e

app :: Application
app = serveWithContext api ctx serverWithExceptionsHandled
        where ctx = checkBasicAuth :. EmptyContext
服务器::服务器API 服务器=ping :注册 :辛格 :帐户 :getSessions serverWithExceptionsHandled=server`catch`(\e->handleExceptions(e::SomeException)) --|打印到控制台,然后重新旋转 handleExceptions::(MonadIO m,MonadThrow m,Exception e)=>e->m b handleExceptions e=do liftIO$PRINTE 通过 应用程序::应用程序 app=serveWithContext api ctx服务器,处理异常 其中ctx=checkBasicAuth:。空上下文 所有运行的服务器代码都有一个
MonadCatch
实例和一个
MonadThrow
实例。因此,您可以使用以下异常处理程序扭曲服务器代码:

handled :: Server SomeRoute
handled = server1 `catch` (\e -> handleExceptions (e :: SomeException))

type API = SomeRoute :<|> (other routes)

combined :: Server API
combined = handled :<|> (server code for other routes)

app :: Application
app = serve @API Proxy combined

更多示例:

ping' = ping `catch` (\e -> handleExceptions (e :: SomeException))

server :: Server API
server = ping'
    :<|> signup
    :<|> singin
    :<|> account
    :<|> getSessions
ping'=ping`catch`(\e->handleExceptions(e::SomeException))
服务器::服务器API
服务器=ping'
:注册
:辛格
:帐户
:getSessions
所有运行的服务器代码都有一个
MonadCatch
实例和一个
MonadThrow
实例。因此,您可以使用以下异常处理程序扭曲服务器代码:

handled :: Server SomeRoute
handled = server1 `catch` (\e -> handleExceptions (e :: SomeException))

type API = SomeRoute :<|> (other routes)

combined :: Server API
combined = handled :<|> (server code for other routes)

app :: Application
app = serve @API Proxy combined

更多示例:

ping' = ping `catch` (\e -> handleExceptions (e :: SomeException))

server :: Server API
server = ping'
    :<|> signup
    :<|> singin
    :<|> account
    :<|> getSessions
ping'=ping`catch`(\e->handleExceptions(e::SomeException))
服务器::服务器API
服务器=ping'
:注册
:辛格
:帐户
:getSessions

谢谢!介意我问一个问题吗:我得到以下错误:
没有因使用“catch”(catch)而产生的(MonadCatch((:)(Servant.Handler(Map.Map String)))实例。
我如何修复它?(请参阅更新)@Nik您对
服务器的定义是什么?啊,您必须分别为每个服务器组件指定异常处理程序。结果表明,默认情况下,servant打印所有异常,因此使用此处理程序,我将
此异常
打印到
标准输出
两次。但是,我需要修改默认的服务器响应,该响应仍然表示出现了问题。我想我应该为这个特殊的案例提出一个新的问题来强调区别。谢谢!介意我问一个问题吗:我得到以下错误:
没有因使用“catch”(catch)而产生的(MonadCatch((:)(Servant.Handler(Map.Map String)))实例。
我如何修复它?(请参阅更新)@Nik您对
服务器的定义是什么?啊,您必须分别为每个服务器组件指定异常处理程序。结果表明,默认情况下,servant打印所有异常,因此使用此处理程序,我将
此异常
打印到
标准输出
两次。但是,我需要修改默认的服务器响应,该响应仍然表示出现了问题。我想我应该为这个特殊的案例提出一个新的问题来强调两者的区别。