Skip to content

Incompatibility between servant-server and Vanilla JS generator on server-side errors #296

@utdemir

Description

@utdemir

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.

2015-12-16-144902_635x380_scrot

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions