@@ -87,7 +87,7 @@ import Servant.API.ResponseHeaders
87
87
import qualified Servant.Types.SourceT as S
88
88
import Web.HttpApiData
89
89
(FromHttpApiData , parseHeader , parseQueryParam ,
90
- parseUrlPieceMaybe , parseUrlPieces )
90
+ parseUrlPieceMaybe , parseUrlPieces , parseUrlPiece )
91
91
92
92
import Servant.Server.Internal.BasicAuth
93
93
import Servant.Server.Internal.Context
@@ -166,21 +166,23 @@ instance (HasServer a context, HasServer b context) => HasServer (a :<|> b) cont
166
166
-- > server = getBook
167
167
-- > where getBook :: Text -> Handler Book
168
168
-- > getBook isbn = ...
169
- instance (KnownSymbol capture , FromHttpApiData a , HasServer api context )
169
+ instance (KnownSymbol capture , FromHttpApiData a , HasServer api context , SBoolI ( FoldLenient mods ) )
170
170
=> HasServer (Capture' mods capture a :> api ) context where
171
171
172
172
type ServerT (Capture' mods capture a :> api ) m =
173
- a -> ServerT api m
173
+ If ( FoldLenient mods ) ( Either String a ) a -> ServerT api m
174
174
175
175
hoistServerWithContext _ pc nt s = hoistServerWithContext (Proxy :: Proxy api ) pc nt . s
176
176
177
177
route Proxy context d =
178
178
CaptureRouter $
179
179
route (Proxy :: Proxy api )
180
180
context
181
- (addCapture d $ \ txt -> case parseUrlPieceMaybe txt of
182
- Nothing -> delayedFail err400
183
- Just v -> return v
181
+ (addCapture d $ \ txt -> case ( sbool :: SBool (FoldLenient mods )
182
+ , parseUrlPiece txt :: Either T. Text a ) of
183
+ (SFalse , Left e) -> delayedFail err400 { errBody = cs e }
184
+ (SFalse , Right v) -> return v
185
+ (STrue , piece) -> return $ (either (Left . cs) Right ) piece
184
186
)
185
187
186
188
-- | If you use 'CaptureAll' in one of the endpoints for your API,
0 commit comments