haskell-servant / haskell-servant/servant
servant-server returns errors that don't go through a formatter
- Dominant language
- Haskell
- Stars
- 2k
- Forks
- 427
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 5
Description
405 "Method Not Allowed" isn't formatted:
```shellsession
$ curl -v http://localhost:8080/post-endpoint
* Trying ::1:8080...
* Connected to localhost (::1) port 8080 (#0)
> GET /post-endpoint HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.70.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 405 Method Not Allowed
< Transfer-Encoding: chunked
< Date: Sat, 26 Sep 2020 16:33:56 GMT
< Server: Warp/3.3.12
<
* Connection #0 to host localhost left intact
```
404 "Not Found" is formatted:
```shellsession
$ curl -v http://localhost:8080/nonexistent-endpoint
* Trying ::1:8080...
* Connected to localhost (::1) port 8080 (#0)
> GET /nonexistent-endpoint HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.70.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 404 Not Found
< Transfer-Encoding: chunked
< Date: Sat, 26 Sep 2020 17:01:22 GMT
< Server: Warp/3.3.12
< Content-Type: application/json
<
* Connection #0 to host localhost left intact
{"msg":"Not found path: /other-endpoint"}
```
You can see the various places where unformatted errors are returned in the code:
```shellsession
$ git grep -E 'Fail.*err[0-9]+' servant-server/src
servant-server/src/Servant/Server.hs: routerLayout (route p context (emptyDelayed (FailFatal err501)))
servant-server/src/Servant/Server/Internal.hs: | otherwise = delayedFail err405
servant-server/src/Servant/Server/Internal.hs: | otherwise = delayedFail err406
servant-server/src/Servant/Server/Internal.hs: Nothing -> FailFatal err406 -- this should not happen (checked before), so we make it fatal if it does
servant-server/src/Servant/Server/Internal.hs: accCheck = when (isNothing cmediatype) $ delayedFail err406
servant-server/src/Servant/Server/Internal.hs: Nothing -> delayedFail err415
servant-server/src/Servant/Server/Internal/BasicAuth.hs: Unauthorized -> delayedFailFatal err403
servant-server/src/Servant/Server/Internal/BasicAuth.hs: where plzAuthenticate = delayedFailFatal err401 { errHeaders = [mkBAChallengerHdr realm] }
```
Contributor guide
Assessment
This issue has not been assessed yet.