ntent → ActionM ()
setContent device = \case
  NoContent → pure ()
  TextContent t → check t >>= Scotty.text
  HtmlContent h → check (h device |> toHtml |> renderHtml) >>= Scotty.html
  JSONContent j → check j >>= Scotty.json
 where
  check ∷ NFData α ⇒ α → ActionM α
  check x =
    liftIO
      (
        (Right <$> (x |> force |> evaluate))
        `catch`
        (\(e ∷ SomeException) → pure $ Left e)
      )
    >>=
    \case
      Right result → pure result
      Left exc → do
        logIO "ERROR RENDERING PAGE CONTENT:"
        logIO $ pack $ displayException exc
        Scotty.raise "A server error occurred when rendering the page content.  Please try reloading the page."

setStatusAndLog ∷ Status → ActionM ()
setStatusAndLog
setContent ∷ Device → Content → ActionM ()
setContent device = \case
  NoContent → pure ()
  TextContent t → check t >>= Scotty.text
  HtmlContent h → check (h device |> toHtml |> renderHtml) >>= Scotty.html
  JSONContent j → check j >>= Scotty.json
 where
  check ∷ NFData α ⇒ α → ActionM α
  check x =
    liftIO
      (
        (Right <$> (x |> force |> evaluate))
        `catch`
        (\(e ∷ SomeException) → pure $ Left e)
      )
    >>=
    \case
      Right result → pure result
      Left exc → do
        logIO "ERROR RENDERING PAGE CONTENT:"
        logIO $ pack $ displayException exc
        Scotty.raise "A server error occurred when rendering the page content.  Please try reloading the page."
setContent device = \case
  NoContent → pure ()
  TextContent t → check t >>= Scotty.text
  HtmlContent h → check (h device |> toHtml |> renderHtml) >>= Scotty.html
  JSONContent j → check j >>= Scotty.json
 where
  check ∷ NFData α ⇒ α → ActionM α
  check x =
    liftIO
      (
        (Right <$> (x |> force |> evaluate))
        `catch`
        (\(e ∷ SomeException) → pure $ Left e)
      )
    >>=
    \case
      Right result → pure result
      Left exc → do
        logIO "ERROR RENDERING PAGE CONTENT:"
        logIO $ pack $ displayException exc
        Scotty.raise "A server error occurred when rendering the page content.  Please try reloading the page."