The following code is part of a controller in a Quarkus Microprofile API application.
@GET
@Path("/limit/{limit}/offset/{offset}")
@Produces(MediaType.APPLICATION_JSON)
public Response paginatedAccounts(
@Parameter(
description = "Number of records to be returned.",
required = true,
schema = @Schema(type = SchemaType.INTEGER))
@PathParam("limit") int limit,
@Parameter(
description = "The starting number of record, zero based.",
required = true,
schema = @Schema(type = SchemaType.INTEGER))
@PathParam("offset") int offset)
{
return Response
.ok(this.accountService.getPaginatedAccounts(limit, offset))
.build();
}
It returns a paginated list of accounts.
When user calls the API providing a wrong type for "limit" or "offset", ie:
http://[url]/[entity]/limit/zzz/offset/0
she receives "404 - Not Found"
How to validate the parameters "limit" and "offset" so that when user supplies a wrong type (string for int) she receives instead:
"400 - Bad Request"
as it should be?