How to handle DataProvider errors in a Grid

I have a Grid display where the data provider is paged in from a REST based request. Like any network requests there are a multitude of errors that can occur but I can’t find any way to catch the errors and display a message to explain why the new data isn’t available and give the option to try again.

Is there some feature or trick that I can’t see where an onError type listener can be attached to the grid so when a failure occurs it doesn’t just generate a 500 error and page fails to load.

The problem as far as I can see at the moment is due to paging being called from the DataCommunicator which doesn’t have any error handling when fetching either the page or when querying the size.

I’m gonna link you some v8 material, but I think this might work on flow too. You can throw specific exceptions which you can handle one by one in your handler. I see there’s a method VaadinSession.getCurrent().setErrorHandler(ErrorHandler)

https://vaadin.com/docs/v8/framework/application/application-errors.html

Unless I’m miss reading it that approach would allow you to navigate to a new page and display the appropriate message. That would be fine if the error is a fatal one however I can’t see it working for in cases where you want to retry.

Ross Mark:
Unless I’m miss reading it that approach would allow you to navigate to a new page and display the appropriate message. That would be fine if the error is a fatal one however I can’t see it working for in cases where you want to retry.

Not necessarily, here’s my idea.

I’d do this: when I throw the exception around the grid (eg. in the containing Div), I’d issue the REST request in such a manner that if the exception is thrown, I’d wrap the exception in another Throwable (eg. FooThrowable) so that it includes a reference to the Grid itself, and perhaps the entered query data. And when this exception is “bubbled” to the ErrorHandler (as I’ve mentioned above), the ErrorHandler could just show a Dialog, with a “retry” button. If that is pressed, then the Grid is reloaded again with the new data based in the String which is retrieved together with the reference to the Grid by issuing ((FooThrowable) ErrorEvent.getThrowable()).getGrid(). and ... .getText(). Something like that.

https://vaadin.com/components/vaadin-dialog/java-examples