【问题标题】:Send user defined error message to React JS from responseEntity从 responseEntity 向 React JS 发送用户定义的错误消息
【发布时间】:2017-12-21 15:03:52
【问题描述】:

我的 java 代码有一个超级代理调用。在那个 Java 控制器中 - 我正在抛出用户定义的异常消息,如下所示。

服务中:

if (user_id == null){
   throw new Exception("User ID is missing!!!");
}

在控制器中:

Map<String, String> resp = new HashMap<String,String>();
   try{
     String returnValue= myserviceobj.myservicemethod;
   }catch(Exception e){
     resp.put("status","ERROR");
     resp.put("message",e.getMessage());
     return new ResponseEntity<Map<String,String>>(resp, HttpStatus.Bad_Response);
}

在 React Js 中,我使用 superagent 进行服务调用。我不确定如何在 UI 中访问该用户定义的异常消息。

这是我在 JS 中所做的:

webservice(data, actionName, (error,resp){
   if(error){
     //call alert and send the user defined message.
   }
})

【问题讨论】:

  • 您的意思是您希望添加警报组件或类似服务处理程序的东西?
  • 在 JS 端我必须在警报中显示该消息
  • 请查看更新后的答案。

标签: javascript java reactjs


【解决方案1】:

https://developer.mozilla.org/fr/docs/Web/API/Window/alert ?

无论如何我都会使用 Redux 来检查我的应用程序的状态并发送警报操作。

也许这就是你要找的东西:https://alexanderpaterson.com/posts/showing-and-dismissing-alerts-in-a-react-application

【讨论】:

  • 感谢您的回复...我实际上正在寻找一种访问它的方法。抱歉,我提到的是“显示消息”而不是访问
猜你喜欢
  • 2015-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-08
  • 2019-07-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多