{- |
  This module contains a `ScottyError` error type that short-cuts to http
  response types.
-}
module Network.Legion.Discovery.HttpError (
  HttpError,
) where

import Data.Text (Text, pack)
import Data.Text.Lazy (fromStrict)
import Network.HTTP.Types (Status)
import Web.Scotty.Trans (ScottyError, stringError, showError)

data HttpError
  = Transient Status Text
  | Critical Text

instance ScottyError HttpError where
  stringError = Critical . pack
  showError (Transient _ msg) = fromStrict msg
  showError (Critical msg) = fromStrict msg