2014-05-13 69 views

回答

11

您可以添加自己的WebApplicationException子是這樣的:

public class ObjectNotFoundException extends WebApplicationException { 

    public ObjectNotFoundException() { 
    super(Responses.notFound().build()); 
    } 

    public ObjectNotFoundException(String message) { 
    super(Response.status(Responses.NOT_FOUND). 
    entity(message).type("text/plain").build()); 
    } 

} 

更多信息請參見the documentation。如果這對您的應用程序更有意義,也可以使用ExceptionMappers

+1

對不起,不得不作出編輯撤消我在一小時前(或左右)發生的意外downvote, –