[发生异常时需要发送HTTP错误500

问题描述 投票:0回答:1

我已经使用struts2-rest-plugin设计了RESTful后端。我的前端是Ember.js CRUD应用。

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

如何将其作为HTTP错误代码500发送到我的ember.js应用程序?

rest exception struts2 http-status-code-500 struts2-rest-plugin
1个回答
0
投票

对于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());
    }
© www.soinside.com 2019 - 2024. All rights reserved.