Fix jsonError api route.

This commit is contained in:
Dillon Kearns 2021-12-31 11:17:12 -08:00
parent 3aae8c1adf
commit 78ee8d0117

View File

@ -33,25 +33,32 @@ routes getStaticRoutes htmlToString =
]
jsonError : Server.Request.ServerRequest ServerResponse.ServerResponse
jsonError : ApiRoute ApiRoute.Response
jsonError =
Server.Request.oneOf
[ Server.Request.jsonBodyResult (Decode.field "name" Decode.string)
|> Server.Request.map
(\result ->
case result of
Ok firstName ->
ServerResponse.stringBody
("Hello " ++ firstName)
ApiRoute.succeed
(Server.Request.oneOf
[ Server.Request.jsonBodyResult (Decode.field "name" Decode.string)
|> Server.Request.map
(\result ->
case result of
Ok firstName ->
ServerResponse.stringBody
("Hello " ++ firstName)
Err decodeError ->
decodeError
|> Json.Decode.errorToString
|> ServerResponse.stringBody
|> ServerResponse.withStatusCode 400
)
, Server.Request.succeed (ServerResponse.stringBody "Hello anonymous!")
]
Err decodeError ->
decodeError
|> Json.Decode.errorToString
|> ServerResponse.stringBody
|> ServerResponse.withStatusCode 400
)
, Server.Request.succeed (ServerResponse.stringBody "Hello anonymous!")
]
|> Server.Request.map DataSource.succeed
)
|> ApiRoute.literal "api"
|> ApiRoute.slash
|> ApiRoute.literal "validate-json"
|> ApiRoute.serverRender
greet : ApiRoute ApiRoute.Response