Fix #23971: Give a nicer error message when a server is down

Signed-off-by: Taylor Smock <tsmock@meta.com>
pull/49/head v833
Taylor Smock 2024-10-21 07:28:26 -06:00
rodzic 817b633660
commit 629e34f413
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 3D4E7B422350E843
1 zmienionych plików z 9 dodań i 3 usunięć

Wyświetl plik

@ -38,6 +38,7 @@ import org.openstreetmap.josm.gui.progress.ProgressMonitor;
import org.openstreetmap.josm.gui.progress.swing.PleaseWaitProgressMonitor;
import org.openstreetmap.josm.gui.util.GuiHelper;
import org.openstreetmap.josm.io.IllegalDataException;
import org.openstreetmap.josm.io.OsmApiException;
import org.openstreetmap.josm.io.OsmTransferException;
import org.openstreetmap.josm.plugins.mapwithai.MapWithAIPlugin;
import org.openstreetmap.josm.plugins.mapwithai.commands.MapWithAIAddCommand;
@ -198,9 +199,14 @@ public final class MapWithAIDataUtils {
original.mergeFrom(ds.join());
} catch (RuntimeException e) {
final String notificationMessage;
final var cause = e.getCause();
if (cause instanceof IllegalDataException illegalDataException) {
notificationMessage = ExceptionUtil.explainException(illegalDataException);
Throwable cause = e.getCause();
if (cause != null) {
while (cause.getCause() != null && RuntimeException.class.equals(cause.getClass())) {
cause = cause.getCause();
}
}
if (cause instanceof IllegalDataException) {
notificationMessage = ExceptionUtil.explainException((Exception) cause);
Logging.trace(e);
final var notification = new Notification();
GuiHelper.runInEDT(() -> notification.setContent(notificationMessage));