如何从GWT的客户端向服务器发送Exception对象?

时间:2022-08-29 09:53:20

I'm trying to log client's exceptions on the server side. So I need to send them from client to server.

我正在尝试在服务器端记录客户端的异常。所以我需要将它们从客户端发送到服务器。

I have created service for this purpose:

我为此目的创建了服务:

public interface LoggerService extends RemoteService {
    void logerror(Throwable e);
}

On the client's side I use GWT.setUncaughtExceptionHandler(uncaughtExceptionHandler):

在客户端,我使用GWT.setUncaughtExceptionHandler(uncaughtExceptionHandler):

GWT.UncaughtExceptionHandler uncaughtExceptionHandler = new
    GWT.UncaughtExceptionHandler() {
          public void onUncaughtException(Throwable e) {

            LoggerServiceAsync loggerService = GWT.create(LoggerService.class);
            loggerService.logerror(e, new AsyncCallback<Void>() {
                @Override
                public void onSuccess(Void arg0) {
                    SC.say("Client's error logged");

                }
                @Override
                public void onFailure(Throwable arg0) {
                    SC.say("Unable to log client's error");

                }
            });  
          }
        };

When I'm using hosted mode it works fine. But when I'm trying to work with web mode My LoggerService doesn't work. I know that in hosted mode exception "translates" from js to java. But I can't understand, why my logerror(Throwable e) method doesn't invoke at all in web mode. Server responce is 200.

当我使用托管模式时,它工作正常。但是,当我尝试使用Web模式时,我的LoggerService不起作用。我知道在托管模式下异常“从js转换”到java。但我无法理解,为什么我的logerror(Throwable e)方法在web模式下根本不会调用。服务器响应是200。

2 个解决方案

#1


0  

GWT offers infrastructure that facilitates client side logging with support for sending your log messages to the server. It'll slightly complicate your implementation at first but might establish a way to do logging across your app.

GWT提供便于客户端日志记录的基础架构,并支持将日志消息发送到服务器。它最初会使您的实现稍微复杂化,但可能会建立一种在您的应用程序中进行日志记录的方法。

#2


0  

Finally I added gwt-log for logging client's exceptions on server.

最后,我添加了gwt-log来记录客户端在服务器上的异常。

#1


0  

GWT offers infrastructure that facilitates client side logging with support for sending your log messages to the server. It'll slightly complicate your implementation at first but might establish a way to do logging across your app.

GWT提供便于客户端日志记录的基础架构,并支持将日志消息发送到服务器。它最初会使您的实现稍微复杂化,但可能会建立一种在您的应用程序中进行日志记录的方法。

#2


0  

Finally I added gwt-log for logging client's exceptions on server.

最后,我添加了gwt-log来记录客户端在服务器上的异常。