Skip to content
Permalink
Browse files

Return a 404 when we can't find a matching user

  • Loading branch information...
bradparker committed Oct 2, 2019
1 parent 10aa133 commit 2521f341f5114a83aff7dd4e13c83c604c98bfee
Showing with 6 additions and 1 deletion.
  1. +1 −0 how-does-servants-type-dsl-work.cabal
  2. +5 −1 src/Main.hs
@@ -10,6 +10,7 @@ executable server
main-is: Main.hs
build-depends: base ^>=4.12.0.0
, aeson
, mtl
, servant-server
, time
, wai
@@ -6,6 +6,9 @@

module Main where

import Control.Monad.Error.Class
( throwError
)
import Data.Aeson (ToJSON)
import Data.Foldable (find)
import Data.Proxy (Proxy(Proxy))
@@ -21,6 +24,7 @@ import Servant
, Handler
, JSON
, Server
, err404
, serve
)

@@ -72,7 +76,7 @@ matchesUsername uname = (uname ==) . username
usersShow :: String -> Handler User
usersShow uname =
case find (matchesUsername uname) users of
Nothing -> _
Nothing -> throwError err404
Just user -> pure user

usersServer :: Server UsersAPI

0 comments on commit 2521f34

Please sign in to comment.
You can’t perform that action at this time.