you're telling me a puppy coded this??
module Data.Result where

import Data.Aeson (ToJSON, encode, (.=), object)
import Network.Wai (Response, responseLBS)
import qualified Data.ByteString      as BS
import qualified Data.ByteString.Lazy as LBS
import qualified Data.Text.Encoding   as T

data Result
  = forall j. ToJSON j => Value j
  | Bytes { contentType :: BS.ByteString, body :: LBS.ByteString }
  | Error { statusCode :: Int, errorMessage :: LBS.ByteString }
  | Empty

toResponse :: Result -> Response
toResponse = \case
  Value json -> responseLBS
    (toEnum 200)
    [("content-type", "application/activity+json")]
    (encode json)
  Bytes contentType body -> responseLBS
    (toEnum 200)
    [("content-type", contentType)]
    body
  Error code body -> responseLBS
    (toEnum code)
    [("content-type", "application/json")]
    (encode $ object [ "error" .= T.decodeUtf8 (BS.toStrict body) ])
  Empty -> responseLBS (toEnum 202) [] ""

getStatusCode :: Result -> Int
getStatusCode = \case
  Bytes _ _    -> 200
  Empty        -> 202
  Error code _ -> code
  Value _      -> 200