I am using jersey with spring boot, and I have a exception mapper:
package org.smarter.providers;
import com.google.common.collect.ImmutableMap;
import org.smarter.exception.ApiException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.Provider;
import java.util.Optional;
import static org.smarter.exception.UserException.UNAUTHORIZED;
@Provider
public class ExceptionMapper implements javax.ws.rs.ext.ExceptionMapper<ApiException> {
@Override
public Response toResponse(ApiException exception) {
return Response.status(status(exception)).build();
}
private Integer status(ApiException exception) {
return Optional.ofNullable(ImmutableMap.<String, Integer>builder()
.put(UNAUTHORIZED, 401)
.build()
.get(exception.code()))
.orElse(404);
}
}
Also registered, and using debug, i can see this mapper get invoked correctly, but how ever the final response still returning 404, no matter using junit test or manual test.
Here is the test:
when()
.get("/users/current/memos/daily")
.then()
.statusCode(401);
And then registered in Jersey Configuration:
register(ExceptionMapper.class);
I am using jersey with spring boot, and don't know how to trouble shooting on this. any advice will be appreciated.