-
-
Notifications
You must be signed in to change notification settings - Fork 418
Open
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.