Reputation: 12107
Where can I find, in the Suave docs, the way to return an http error with a message as a plain text error?
I keep looking and I just can't find my way through the docs since it's structured as bits of examples here and there.
What I would like to do is this:
if thingsGoWell then
OK myResult
else
ERROR someHttpStatusCode myString
I know I can use the presets, like
INTERNAL_ERROR "hello"
but I want to be able to pass my own HttpStatusCode.
I'm just beginning to use Suave, I like the concepts so far but I'm really struggling with the documentation style.
Upvotes: 0
Views: 71
Reputation: 17038
I think you're looking for the basic response
function:
val response : statusCode:HttpCode -> content:byte [] -> WebPart
Documentation is here. Usage is like this:
response HTTP_501 (UTF8.bytes message)
I agree with you that the Suave documentation isn't great. Personally, I often answer questions like this by simply looking in the source code, which is here. I have a local copy that I've cloned and built. It's pretty easy, actually.
As an example, in this case, I searched for "INTERNAL_ERROR", since you gave that as a hint, and found this implementation:
let internal_error arr = response HTTP_500 arr
let INTERNAL_ERROR message = internal_error (UTF8.bytes message)
From that, I was able to construct an answer to your question, and then googled the relevant documentation as well.
Upvotes: 0