【问题标题】:Need to Send HTTP-error-500 when an Exception occurs发生异常时需要发送 HTTP-error-500
【发布时间】:2019-10-15 12:30:58
【问题描述】:

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

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

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

【问题讨论】:

标签: rest exception struts2 http-status-code-500 struts2-rest-plugin


【解决方案1】:

如果是 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());
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-08
    • 1970-01-01
    • 2022-11-09
    • 2014-04-22
    相关资源
    最近更新 更多