2

I have POST action that ends in a custom IO operation. The server sends a 500 Internal Server Error even if the operation was successful. I need to send a custom response to deal with this. How should I do this?

My action is like this:

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

How should I build customResponse?

Varun Rajput
  • 235
  • 1
  • 7

1 Answers1

2

So customIO has type customIO :: IO Response?

If that's the case you can do:

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.

Marc Scholten
  • 1,351
  • 3
  • 5