Reputation: 125
I am using EasyCron (https://www.easycron.com) to ping an endpoint in my IHP app.
If the code on my app's side fails for some reason, I would like to set the HTTP status code to 503 or similar and display the errors in the response so that,
Since my response is not going to be parsed by EasyCron, I don't need it to be in JSON format. It's just going to be saved in the logs.
I see that there is renderJsonWithStatusCode
but since I have no need to parse the JSON and it is extra work to create JSON instances of my data, I would prefer to render a plain text response but with a custom status code. Is this possible?
Upvotes: 1
Views: 65
Reputation: 1396
You can set a custom status code by calling IHP's respondAndExit
with a custom response:
import Network.Wai (responseLBS)
import Network.HTTP.Types (status503)
import Network.HTTP.Types.Header (hContentType)
action MyAction = do
let text = "An error happend"
respondAndExit $ responseLBS status503 [(hContentType, "text/plain")] text
Upvotes: 2