【发布时间】:2020-04-14 16:02:37
【问题描述】:
默认情况下,即使请求的端点返回 JSON,Servant 也会返回纯字符串请求
$ http $S/signup email=mail@domain.com
HTTP/1.1 400 Bad Request
Connection: keep-alive
Date: Tue, 14 Apr 2020 15:59:32 GMT
Server: nginx/1.17.9 (Ubuntu)
Transfer-Encoding: chunked
Error in $: parsing Credentials.Credentials(Credentials) failed, key "password" not found
我正在尝试将这些字符串包装成简单的JSON 字典:
$ http $S/signup email=mail@domain.com
HTTP/1.1 400 Bad Request
Connection: keep-alive
Date: Tue, 14 Apr 2020 15:59:32 GMT
Server: nginx/1.17.9 (Ubuntu)
Transfer-Encoding: chunked
{"error": "Error in $: parsing Credentials.Credentials(Credentials) failed, key \"password\" not found"}
但看起来没那么容易。
这个问题说明了可能的解决方案,但我今天无法让它们工作Custom JSON errors for Servant-server
在此线程 https://github.com/haskell-servant/servant/issues/732 中讨论了另一种方法,但对于这样一个简单的任务来说似乎有点过头了。
不知道2020年有没有简单稳健的解决方案?
【问题讨论】: