Skip to content

Instantly share code, notes, and snippets.

@qrilka
Created April 27, 2018 08:43
Show Gist options
  • Save qrilka/49b0634fce17bcbd2cd4abea503a0f8c to your computer and use it in GitHub Desktop.
Save qrilka/49b0634fce17bcbd2cd4abea503a0f8c to your computer and use it in GitHub Desktop.
Bad response for an exception
qrilka@qdesktop ~ $ curl -v localhost:8080/evaluated
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /evaluated HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.59.0
> Accept: */*
>
* HTTP 1.0, assume close after body
< HTTP/1.0 500 Internal Server Error
< Date: Fri, 27 Apr 2018 08:42:36 GMT
< Server: Warp/3.2.17
< Content-Type: text/plain; charset=utf-8
<
* Closing connection 0
Something went wrongqrilka@qdesktop ~ $ curl -v localhost:8080/unevaluated
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /unevaluated HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.59.0
> Accept: */*
>
* Empty reply from server
* Connection #0 to host localhost left intact
curl: (52) Empty reply from server
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wall -Werror #-}
module Main (main) where
import Network.Wai.Handler.Warp (run)
import Servant
type API =
"evaluated" :> Get '[JSON] String
:<|>
"unevaluated" :> Get '[JSON] String
main :: IO ()
main = run 8080 $ serveWithContext (Proxy :: Proxy API) (True :. EmptyContext) server
where
server :: Server API
server = evaluated :<|> unevaluated
evaluated = error "evaluated"
unevaluated = return $ error "evaluated"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment