发生异常时需要发送 HTTP-error-500



我使用struts2-rest-plugin设计了一个 RESTful 后端。 我的前端是Ember.jsCRUD应用程序。

当我尝试使用重复ID创建新记录时,我的服务器是 显示异常。

如何将其作为 HTTP-error-code-500 发送到我的 ember.js 应用程序?

在Struts的情况下,我只需要返回DefaultHttpHeaders。

public HttpHeaders create() {
try{
employeesService.save(model);
}
catch(Exception e){
System.out.println(e);
return new DefaultHttpHeaders("DuplicateId").withStatus(409);
}
return new DefaultHttpHeaders("success")
.setLocationId(model.getId());
}

最新更新