Getting Navigation Exception from (only) consuming REST-API

I develop my Application with Vaadin Designer. Each Designer-File has it’s associated Java-Class (Attachment 1). So i have a view called “company” which is accessible with the URL “…/company”. When this route is called, the company site gets rendered and in the constructor of the Java-Class i pass an instance of my Rest-Client (I am using OpenFeign-Client provided by SpringBoot cloud). The client performs HTTP-Requests to service A, that retrieves static content to be displayed in the page . When this service A is up, everything works fine and the content gets displayed within the page.

What the application does when Service A isn’t up or the content isn’t accessible? I handle these Exceptions with the ResponseErrorDecoder of the OpenFeign-Client based on the status code. (Attachment 2)

BUT now the problem:
I turn off service A, so the content is not retrievable. The Rest-Client throws an Exception and the whole Error-Stack is shown in an Error-View. The Root-Cause of this Error is the exception i have thrown.
I red about it, that there are 2 ways to handle exceptions in vaadin: navigation exceptions to handle with router support and custom exceptions.
Navigation exceptions are intended to navigate to an Error-View.

My goal:
It’s not crucial, that the content can’t get retrieved. I want to display the page without navigating to the Error-View, and displaying the page without the static content and a notification to inform the User about the failure and prompt him to reload the page. So the exception should not be treated as navigation exception to reach this approach.

So my core questions for this post are:

  1. Why Vaadin tells me, that it is a navigation exception?
  2. How can i perform the call to Service A, that it’s not resulting in an navigation exception and not showing Error-View?

Thanks in previous!

You are throwing a exception inside the constructor of the view, making it impossible for Vaadin to create the view on navigating. You can catch the exception and do proper error handling there if the client doesn’t respond correctly by printing e.g. the message of the exception to the view.

Really appreciate for your quick answer! :slightly_smiling_face:
Aah that makes sense, i will try to catch the exception within the constructor and handle it there to see, if i can avoid the Error-View this way.

You can also move your code to e.g. the before or after navigation Event, but you have to handle the exception yourself if you don’t want to have Vaadin handle it :wink:

I like this approach, because the content can be “lazy loaded” and exception handling may then live in one central point → ErrorDecoder of the Rest-Client :slightly_smiling_face:
I will try it out!
When i solve my case, i will post it into here to describe the solution.

I solved this with the afterNavigation-Event, where i handle the thrown exception from my Rest-Client to react properly at the failure of service with a notification to the client.
Thanks for your support @quirky-zebra! :slightly_smiling_face:

This looks better :+1: