[英]Add message error to response body in Jersey
我有这个端点:
@POST
@Path("login")
@Consumes(MediaType.APPLICATION_JSON)
public Response doLogin(LoginCredentials loginCredentials) {
try {
usersService.validate(loginCredentials);
return Response.ok().build();
} catch (InvalidCredentialsException e) {
return Response.status(Response.Status.UNAUTHORIZED).build();
} catch (NotAuthorizedUserException e) {
return Response.status(Response.Status.UNAUTHORIZED).build();
}
}
在UNAUTHORIZED
情况下,我想发送一条消息来指定具体的错误。 怎么办?
在响应情况ok
,我这样做:
返回Response.ok("Some message here").build();
使用实体(对象数据)方法:
Response.status(Response.Status.UNAUTHORIZED).entity("Some message here").build();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.