Got an unexpected behavior on a ContractRoute the ...
# http4k
Got an unexpected behavior on a ContractRoute the route have path lens:
Copy code
val btcPath = <|>().map(::BTC).of("btc")
val spec = "mine" / btcPath
it works if i call
but if the param is not an int ex:
I get a 404 . I was thinking about la lensFailure so 400 or if not catched 500 but not 404. Is it designed that way or is something not right ?
No - this is expected. Route matching is done in a type safe way, so you could have /bob/123 and then /bob/false using 2 different path lenses.
👍 2
Cool feature, but I’m not sure about being the default, or not being able to disable it… At work they want us to detail errors when partners call our APIs. Don’t get me started about the stupidity of wanting every detail, even the details in the json body calls errors (so I have to re-parse the request because the informations in the LensFaliure are non precise enough, and then getting useful informations form Jackson exceptions is not a pice of cake), so they expect a Bad request if the path format is not the type expected not a 404. I guess now I’ll have to check the 404 see if is not a wrong type in the path (not a exciting thing to code)…
I’d do this a slightly different way - make the Path lens really permissive and then handle the error later (after the match has occurred) to try and convert it
Yes you’re right is a better way thanks
If you use asResult() on the path lens and import Result4k then you’ll probably find it easier to do.
(Result4k is an optional dependency on core)
Just make sure you get the one from the fork handles organisation - as we recently migrated it to there.
Yes tried it but finally gone with exceptions as I’m using contracts I’m don’t remember what issue I encountered