2

Java, Jersey

@GET
@Path("/path1")
public String getFunction(
    @QueryParam("param1") Integer intParam1
) {
    ...
}

send get request

  1. http://domain.cc/path1?param1=1222534625474 // overflow Int

  2. http://domain.cc/path1?param1=qweqwe

How to process this errors? I want to catch the error and throw another (my) error

JSK NS
  • 3,346
  • 2
  • 25
  • 42
couatl
  • 416
  • 4
  • 14

3 Answers3

3

https://java.net/jira/browse/JERSEY-1263

@GET
public String get(@QueryParam("count") int count, @ErrorParam Map<String, String> errors) {
    if (!errors.isEmpty()) {
        throw new WebApplicationException(...whatever response you want to generate...);
    }
    ... do whatever you want to do if parameters are fine ...
}
couatl
  • 416
  • 4
  • 14
0

Try the following.

@GET
@Path("/path1")
public String getFunction(
    @QueryParam("param1") String intParam1Str
) {
    Integer intParam1 = null;
    try {
        intParam1 = Integer.parseInt(intParam1Str");
    } catch (Exception e) {
        //do whatever you want
    }
}
V G
  • 18,822
  • 6
  • 51
  • 89
-1

This is because the number you are passing in:

1222534625474

is larger than the largest integer value java can handle: 2^31-1 or 2147483648.

Try setting the parameter type to long:

@GET
@Path("/path1")
public String getFunction(
    @QueryParam("param1") Long intParam1
) {
    ...
}
JSK NS
  • 3,346
  • 2
  • 25
  • 42