haskell-servant / haskell-servant/servant
Incompatibility between servant-server and Vanilla JS generator on server-side errors
- Dominant language
- Haskell
- Stars
- 2k
- Forks
- 427
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 5
Description
Hi.
When any endpoint on servant-server returns a `ServantErr`, it just puts the `errBody` as is. But the JS client generated with `servant-js` expects a JSON object and tries to decode it; then it fails with a syntax error.
I think either the server should encode the errors conforming with `Content-type`, or generated JavaScript client must not convert it from JSON and just give the response body to error callback.
Example:
```
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeOperators #-}
module Main where
--------------------------------------------------------------------------------
import Control.Monad.Except
import Control.Monad.Trans.Class
import Data.Proxy
import Data.Text
import Network.Wai.Handler.Warp
import Servant
import Servant.JS
--------------------------------------------------------------------------------
type API = "stuff" :> Get '[JSON] ()
api :: Proxy API
api = Proxy
server :: Server API
server = throwError $ err500 { errBody="not possible" }
main :: IO ()
main = do
putStrLn . unpack $ jsForAPI api vanillaJS
run 2222 $ serve api server
```
When calling the API with generated JavaScript, instead of calling the error handler, it fails with syntax error.

Contributor guide
Assessment
This issue has not been assessed yet.