1

I have a REST interface implemented with javax to login a user.

@Path("/login")
@GET
@Produces(MediaType.APPLICATION_JSON)
public UserId login(@QueryParam("email") String email, @QueryParam("password") String password) throws InvalidUserDataException {
    User user;
    try {
        user = loadUserFromDatabase(null, email);
    } catch (MissingDatabaseEntryException e) {
        e.printStackTrace();
        throw  new InvalidUserDataException("Email and password do not match.");
    }
    if(!user.confirmed)
        throw new InvalidUserDataException("We have sent you a confirmation mail. Please confirm your email first.");
    if(!user.password.equals(password))
        throw  new InvalidUserDataException("Email and password do not match.");

    return new UserId(user.userId);
}

Furthermore there is an Exception Mapper to map the thrown exceptions to the specific HTTP response.

@Provider
public class InvalidUserDataExceptionHandler implements ExceptionMapper<InvalidUserDataException> {
    @Override
    public Response toResponse(InvalidUserDataException exception)
    {
        return Response.status(Response.Status.CONFLICT).entity(exception.getMessage()).build();
    }
}

No matter what error I am throwing and what status code I am defining in mapper class, the server always responds just with an 500 Internal Server Error instead with the defined 409. Does anybod know what I am missing here? Thanks in advance.

Alex Taylor
  • 8,343
  • 4
  • 25
  • 40
Chinaedu Onwukwe
  • 437
  • 1
  • 7
  • 20

0 Answers0