idmitriev
idmitriev

Reputation: 5054

GWT Handling StatusCodeException

How to get exception from server side, if my service method throws new MyException("Some reason"); I would like to get MyException in onFailure method, but actually I got StatusCodeException. Can I get MyException in order to show error msg on UI : Window.alert(exception.getMessage()); -> prints : "Some reason"

@RemoteServiceRelativePath("reportService.rpc")
public interface ReportService extends RemoteService {
    void saveReport(ReportDTO reportDTO) throws MyException;
}

 @Override
    public void saveReport(ReportDTO reportDTO) throws MyException {
        //Report report = ReportFunc.INST.apply(reportDTO);
        //reportRepository.save(report);
        throw new MyException("Some reason");
    }

 reportServiceAsync.saveReport(reportDTO, new AsyncCallback<Void>() {
                    @Override
                    public void onSuccess(Void result) {
                        Window.alert("Successfully saved");
                    }

                    @Override
                    public void onFailure(Throwable e) {
                        Window.alert(e.getMessage());
                    }
                });

class MyException extends RuntimeException implements Serializable{
  ....
}

Upvotes: 0

Views: 94

Answers (1)

Andrei Volgin
Andrei Volgin

Reputation: 41089

Your exception should extend Exception, not RuntimeException.

Upvotes: 1

Related Questions