IHP - 如何在操作结束时编写自定义响应?

IHP - How to write a custom response at the end of an action?

我有 POST 以自定义 IO 操作结束的操作。即使操作成功,服务器也会发送 500 Internal Server Error。我需要发送自定义响应来处理这个问题。我应该怎么做?

我的操作是这样的:

action MyAction { .. } = do
  .
  .
  .
  customIO
 
 responseStatusShouldBe customResponse status200

我应该如何构建 customResponse

那么 customIO 的类型是 customIO :: IO Response?

如果是这样你可以这样做:

action MyAction = do
    response <- customIO
    respondAndExit response

Here's an example from the IHP codebase itself where ErrorController.buildNotFoundResponse is of type IO Response:

renderNotFound :: (?context :: ControllerContext) => IO ()
renderNotFound = do
    response <- ErrorController.buildNotFoundResponse
    respondAndExit response

The buildNotFoundResponse is defined here.