I have (OData) query params defined in my route like so:
parameters(('$top.as[Int].?, '$skip.as[Int].?)) { (top, skip) =>
I have the following rejection handler to handle all invalid parameters (handleAll):
RejectionHandler.newBuilder()
.handleAll[MalformedQueryParamRejection] { paramRejections =>
// paramRejections is a Seq[MalformedQueryParamRejection]
...
}
The problem is that when called with the following
some-endpoint?$top=invalid&$skip=invalid
The paramRejections
in the rejection handler has 2 entries, both for $top, instead of one for $top and one for $skip.
Seems related to the dollar sign on the params, since when I remove this things work as expected. Is this a known issue or is there a workaround available (that doesn't include removing the dollar sign)?
Note, it seems its only the rejection handler that has a problem with multiple params starting with the dollar sign, since this line in the route correctly assigns top and skip to the variables when $top and $skip are supplied with valid values in the URI:
parameters(('$top.as[Int].?, '$skip.as[Int].?)) { (top, skip) =>
There is an issue with your route tree configuration, probably two candidate routes are evaluated and each one produce a MalformedQueryParamRejection
for the $top
query parameter.
The paramRejections in the rejection handler has 2 entries, both for $top, instead of one for $top and one for $skip.
handleAll
does not collect multiple MalformedQueryParamRejection
originated from the same route, but it collects rejections from different routes.
paramRejections
is a Seq[MalformedQueryParamRejection]
but a single route could be rejected with just one MalformedQueryParamRejection
, specifically (only) the first query parameter not matching the required format.
Try it with a minimal route
configuration (as in the example below) and you'll experience the right behaviour:
val route = get {
parameters(('$top.as[Int].?, '$skip.as[Int].?)) {
(top, skip) => complete(s"$top, $skip")
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With