FlowingCode / ErrorWindowAddon

Error Window Vaadin Add-on
Apache License 2.0
9 stars 2 forks source link

Custom message not shown on Production mode #81

Open FedericoQuarin opened 2 months ago

FedericoQuarin commented 2 months ago

Describe the bug

On production mode, the error window is not showing the custom message that was set, just the error code. errorWindow

Expected behavior

No response

Minimal reproducible example

On the demo, setting production mode and clicking Throw Error with custom message

Add-on Version

4.0.1

Vaadin Version

24

Additional information

No response

javier-godoy commented 2 months ago

In worked that way until 3.7.0 https://github.com/FlowingCode/ErrorWindowAddon/blob/3502b4887bbac413e1dc49ead79d6da2c1f3517b/src/main/java/com/flowingcode/vaadin/addons/errorwindow/ErrorWindow.java#L304-L316

In version 4.0.0 the method was refactored as https://github.com/FlowingCode/ErrorWindowAddon/blob/16fd293860eeb95e07a03726096c03247c5efe40/src/main/java/com/flowingcode/vaadin/addons/errorwindow/ErrorWindow.java#L306-L318

javier-godoy commented 2 months ago

The default error handler initializes errorMessage from the throwable.getLocalizedMessage() (which, regardless of its name, is almost never localized). For unexpected exceptions, it does not make sense to display that information to final users.

You can configure a custom ErrorWindowFactory for a given exception class (and initialize the error window there as you see fit) https://github.com/FlowingCode/ErrorWindowAddon/blob/24aae5a27bff7852529e1afc5997dfc9b2a6045b/src/main/java/com/flowingcode/vaadin/addons/errorwindow/ErrorManager.java#L79-L82

Alternatively, you can provide custom "instructions" and open ErrorWindow explicitly:

https://github.com/FlowingCode/ErrorWindowAddon/blob/24aae5a27bff7852529e1afc5997dfc9b2a6045b/src/test/java/com/flowingcode/vaadin/addons/errorwindow/ErrorwindowDemo.java#L75-L92

javier-godoy commented 1 month ago

The constructor (Throwable, String) seems to suggest that the string will be displayed as "instructions" (in production mode) and that it will override the exception message (in development mode). As explained above, this is not the current intention of the API, but we acknowledge that it's not good DX.