[2512] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.gui;
|
---|
| 3 |
|
---|
| 4 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
|
---|
| 5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
| 6 |
|
---|
| 7 | import java.io.IOException;
|
---|
| 8 | import java.lang.reflect.InvocationTargetException;
|
---|
| 9 | import java.net.HttpURLConnection;
|
---|
| 10 | import java.net.SocketException;
|
---|
| 11 | import java.net.UnknownHostException;
|
---|
[5584] | 12 | import java.util.regex.Matcher;
|
---|
| 13 | import java.util.regex.Pattern;
|
---|
[2512] | 14 |
|
---|
| 15 | import javax.swing.JOptionPane;
|
---|
| 16 |
|
---|
| 17 | import org.openstreetmap.josm.Main;
|
---|
[5275] | 18 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
[2512] | 19 | import org.openstreetmap.josm.io.ChangesetClosedException;
|
---|
[3069] | 20 | import org.openstreetmap.josm.io.IllegalDataException;
|
---|
[2862] | 21 | import org.openstreetmap.josm.io.MissingOAuthAccessTokenException;
|
---|
[7434] | 22 | import org.openstreetmap.josm.io.OfflineAccessException;
|
---|
[6349] | 23 | import org.openstreetmap.josm.io.OsmApi;
|
---|
[2512] | 24 | import org.openstreetmap.josm.io.OsmApiException;
|
---|
| 25 | import org.openstreetmap.josm.io.OsmApiInitializationException;
|
---|
| 26 | import org.openstreetmap.josm.io.OsmTransferException;
|
---|
| 27 | import org.openstreetmap.josm.tools.ExceptionUtil;
|
---|
[10055] | 28 | import org.openstreetmap.josm.tools.bugreport.BugReportExceptionHandler;
|
---|
[2512] | 29 |
|
---|
| 30 | /**
|
---|
| 31 | * This utility class provides static methods which explain various exceptions to the user.
|
---|
| 32 | *
|
---|
| 33 | */
|
---|
[6362] | 34 | public final class ExceptionDialogUtil {
|
---|
[2512] | 35 |
|
---|
| 36 | /**
|
---|
| 37 | * just static utility functions. no constructor
|
---|
| 38 | */
|
---|
| 39 | private ExceptionDialogUtil() {
|
---|
[11921] | 40 | // Hide default constructor for utility classes
|
---|
[2512] | 41 | }
|
---|
| 42 |
|
---|
| 43 | /**
|
---|
| 44 | * handles an exception caught during OSM API initialization
|
---|
| 45 | *
|
---|
| 46 | * @param e the exception
|
---|
| 47 | */
|
---|
| 48 | public static void explainOsmApiInitializationException(OsmApiInitializationException e) {
|
---|
| 49 | HelpAwareOptionPane.showOptionDialog(
|
---|
| 50 | Main.parent,
|
---|
| 51 | ExceptionUtil.explainOsmApiInitializationException(e),
|
---|
| 52 | tr("Error"),
|
---|
| 53 | JOptionPane.ERROR_MESSAGE,
|
---|
| 54 | ht("/ErrorMessages#OsmApiInitializationException")
|
---|
| 55 | );
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | /**
|
---|
| 59 | * handles a ChangesetClosedException
|
---|
| 60 | *
|
---|
| 61 | * @param e the exception
|
---|
| 62 | */
|
---|
| 63 | public static void explainChangesetClosedException(ChangesetClosedException e) {
|
---|
| 64 | HelpAwareOptionPane.showOptionDialog(
|
---|
| 65 | Main.parent,
|
---|
| 66 | ExceptionUtil.explainChangesetClosedException(e),
|
---|
| 67 | tr("Error"),
|
---|
| 68 | JOptionPane.ERROR_MESSAGE,
|
---|
[2598] | 69 | ht("/Action/Upload#ChangesetClosed")
|
---|
[2512] | 70 | );
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | /**
|
---|
| 74 | * Explains an upload error due to a violated precondition, i.e. a HTTP return code 412
|
---|
| 75 | *
|
---|
| 76 | * @param e the exception
|
---|
| 77 | */
|
---|
| 78 | public static void explainPreconditionFailed(OsmApiException e) {
|
---|
| 79 | HelpAwareOptionPane.showOptionDialog(
|
---|
| 80 | Main.parent,
|
---|
| 81 | ExceptionUtil.explainPreconditionFailed(e),
|
---|
| 82 | tr("Precondition violation"),
|
---|
| 83 | JOptionPane.ERROR_MESSAGE,
|
---|
| 84 | ht("/ErrorMessages#OsmApiException")
|
---|
| 85 | );
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | /**
|
---|
| 89 | * Explains an exception with a generic message dialog
|
---|
| 90 | *
|
---|
| 91 | * @param e the exception
|
---|
| 92 | */
|
---|
| 93 | public static void explainGeneric(Exception e) {
|
---|
[6643] | 94 | Main.error(e);
|
---|
[2984] | 95 | BugReportExceptionHandler.handleException(e);
|
---|
[2512] | 96 | }
|
---|
| 97 |
|
---|
| 98 | /**
|
---|
[5266] | 99 | * Explains a {@link SecurityException} which has caused an {@link OsmTransferException}.
|
---|
[2512] | 100 | * This is most likely happening when user tries to access the OSM API from within an
|
---|
| 101 | * applet which wasn't loaded from the API server.
|
---|
| 102 | *
|
---|
| 103 | * @param e the exception
|
---|
| 104 | */
|
---|
| 105 |
|
---|
| 106 | public static void explainSecurityException(OsmTransferException e) {
|
---|
| 107 | HelpAwareOptionPane.showOptionDialog(
|
---|
| 108 | Main.parent,
|
---|
| 109 | ExceptionUtil.explainSecurityException(e),
|
---|
| 110 | tr("Security exception"),
|
---|
| 111 | JOptionPane.ERROR_MESSAGE,
|
---|
| 112 | ht("/ErrorMessages#SecurityException")
|
---|
| 113 | );
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | /**
|
---|
[5266] | 117 | * Explains a {@link SocketException} which has caused an {@link OsmTransferException}.
|
---|
[2512] | 118 | * This is most likely because there's not connection to the Internet or because
|
---|
| 119 | * the remote server is not reachable.
|
---|
| 120 | *
|
---|
| 121 | * @param e the exception
|
---|
| 122 | */
|
---|
| 123 |
|
---|
| 124 | public static void explainNestedSocketException(OsmTransferException e) {
|
---|
| 125 | HelpAwareOptionPane.showOptionDialog(
|
---|
| 126 | Main.parent,
|
---|
| 127 | ExceptionUtil.explainNestedSocketException(e),
|
---|
| 128 | tr("Network exception"),
|
---|
| 129 | JOptionPane.ERROR_MESSAGE,
|
---|
| 130 | ht("/ErrorMessages#NestedSocketException")
|
---|
| 131 | );
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | /**
|
---|
[5266] | 135 | * Explains a {@link IOException} which has caused an {@link OsmTransferException}.
|
---|
[2512] | 136 | * This is most likely happening when the communication with the remote server is
|
---|
| 137 | * interrupted for any reason.
|
---|
| 138 | *
|
---|
| 139 | * @param e the exception
|
---|
| 140 | */
|
---|
| 141 |
|
---|
| 142 | public static void explainNestedIOException(OsmTransferException e) {
|
---|
| 143 | HelpAwareOptionPane.showOptionDialog(
|
---|
| 144 | Main.parent,
|
---|
| 145 | ExceptionUtil.explainNestedIOException(e),
|
---|
| 146 | tr("IO Exception"),
|
---|
| 147 | JOptionPane.ERROR_MESSAGE,
|
---|
| 148 | ht("/ErrorMessages#NestedIOException")
|
---|
| 149 | );
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | /**
|
---|
[5266] | 153 | * Explains a {@link IllegalDataException} which has caused an {@link OsmTransferException}.
|
---|
[7187] | 154 | * This is most likely happening when JOSM tries to load data in an unsupported format.
|
---|
[3069] | 155 | *
|
---|
| 156 | * @param e the exception
|
---|
| 157 | */
|
---|
| 158 | public static void explainNestedIllegalDataException(OsmTransferException e) {
|
---|
| 159 | HelpAwareOptionPane.showOptionDialog(
|
---|
| 160 | Main.parent,
|
---|
| 161 | ExceptionUtil.explainNestedIllegalDataException(e),
|
---|
| 162 | tr("Illegal Data"),
|
---|
| 163 | JOptionPane.ERROR_MESSAGE,
|
---|
| 164 | ht("/ErrorMessages#IllegalDataException")
|
---|
| 165 | );
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | /**
|
---|
[7434] | 169 | * Explains a {@link OfflineAccessException} which has caused an {@link OsmTransferException}.
|
---|
| 170 | * This is most likely happening when JOSM tries to access OSM API or JOSM website while in offline mode.
|
---|
| 171 | *
|
---|
| 172 | * @param e the exception
|
---|
| 173 | * @since 7434
|
---|
| 174 | */
|
---|
| 175 | public static void explainNestedOfflineAccessException(OsmTransferException e) {
|
---|
| 176 | HelpAwareOptionPane.showOptionDialog(
|
---|
| 177 | Main.parent,
|
---|
| 178 | ExceptionUtil.explainOfflineAccessException(e),
|
---|
| 179 | tr("Offline mode"),
|
---|
| 180 | JOptionPane.ERROR_MESSAGE,
|
---|
| 181 | ht("/ErrorMessages#OfflineAccessException")
|
---|
| 182 | );
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 | /**
|
---|
[5266] | 186 | * Explains a {@link InvocationTargetException }
|
---|
[2512] | 187 | *
|
---|
| 188 | * @param e the exception
|
---|
| 189 | */
|
---|
| 190 | public static void explainNestedInvocationTargetException(Exception e) {
|
---|
[8470] | 191 | InvocationTargetException ex = ExceptionUtil.getNestedException(e, InvocationTargetException.class);
|
---|
[2512] | 192 | if (ex != null) {
|
---|
| 193 | // Users should be able to submit a bug report for an invocation target exception
|
---|
| 194 | //
|
---|
| 195 | BugReportExceptionHandler.handleException(ex);
|
---|
| 196 | return;
|
---|
| 197 | }
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | /**
|
---|
[5266] | 201 | * Explains a {@link OsmApiException} which was thrown because of an internal server
|
---|
[2512] | 202 | * error in the OSM API server.
|
---|
| 203 | *
|
---|
| 204 | * @param e the exception
|
---|
| 205 | */
|
---|
| 206 |
|
---|
| 207 | public static void explainInternalServerError(OsmTransferException e) {
|
---|
| 208 | HelpAwareOptionPane.showOptionDialog(
|
---|
| 209 | Main.parent,
|
---|
| 210 | ExceptionUtil.explainInternalServerError(e),
|
---|
| 211 | tr("Internal Server Error"),
|
---|
| 212 | JOptionPane.ERROR_MESSAGE,
|
---|
| 213 | ht("/ErrorMessages#InternalServerError")
|
---|
| 214 | );
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | /**
|
---|
[5266] | 218 | * Explains a {@link OsmApiException} which was thrown because of a bad
|
---|
[2512] | 219 | * request
|
---|
| 220 | *
|
---|
| 221 | * @param e the exception
|
---|
| 222 | */
|
---|
| 223 | public static void explainBadRequest(OsmApiException e) {
|
---|
| 224 | HelpAwareOptionPane.showOptionDialog(
|
---|
| 225 | Main.parent,
|
---|
| 226 | ExceptionUtil.explainBadRequest(e),
|
---|
| 227 | tr("Bad Request"),
|
---|
| 228 | JOptionPane.ERROR_MESSAGE,
|
---|
| 229 | ht("/ErrorMessages#BadRequest")
|
---|
| 230 | );
|
---|
| 231 | }
|
---|
| 232 |
|
---|
| 233 | /**
|
---|
[5266] | 234 | * Explains a {@link OsmApiException} which was thrown because a resource wasn't found
|
---|
[2512] | 235 | * on the server
|
---|
| 236 | *
|
---|
| 237 | * @param e the exception
|
---|
| 238 | */
|
---|
| 239 | public static void explainNotFound(OsmApiException e) {
|
---|
| 240 | HelpAwareOptionPane.showOptionDialog(
|
---|
| 241 | Main.parent,
|
---|
| 242 | ExceptionUtil.explainNotFound(e),
|
---|
| 243 | tr("Not Found"),
|
---|
| 244 | JOptionPane.ERROR_MESSAGE,
|
---|
| 245 | ht("/ErrorMessages#NotFound")
|
---|
| 246 | );
|
---|
| 247 | }
|
---|
| 248 |
|
---|
| 249 | /**
|
---|
[5266] | 250 | * Explains a {@link OsmApiException} which was thrown because of a conflict
|
---|
[2512] | 251 | *
|
---|
| 252 | * @param e the exception
|
---|
| 253 | */
|
---|
| 254 | public static void explainConflict(OsmApiException e) {
|
---|
| 255 | HelpAwareOptionPane.showOptionDialog(
|
---|
| 256 | Main.parent,
|
---|
| 257 | ExceptionUtil.explainConflict(e),
|
---|
| 258 | tr("Conflict"),
|
---|
| 259 | JOptionPane.ERROR_MESSAGE,
|
---|
| 260 | ht("/ErrorMessages#Conflict")
|
---|
| 261 | );
|
---|
| 262 | }
|
---|
| 263 |
|
---|
| 264 | /**
|
---|
[5266] | 265 | * Explains a {@link OsmApiException} which was thrown because the authentication at
|
---|
[2748] | 266 | * the OSM server failed
|
---|
| 267 | *
|
---|
| 268 | * @param e the exception
|
---|
| 269 | */
|
---|
| 270 | public static void explainAuthenticationFailed(OsmApiException e) {
|
---|
| 271 | String msg;
|
---|
[6349] | 272 | if (OsmApi.isUsingOAuth()) {
|
---|
[2748] | 273 | msg = ExceptionUtil.explainFailedOAuthAuthentication(e);
|
---|
| 274 | } else {
|
---|
| 275 | msg = ExceptionUtil.explainFailedBasicAuthentication(e);
|
---|
| 276 | }
|
---|
| 277 |
|
---|
| 278 | HelpAwareOptionPane.showOptionDialog(
|
---|
| 279 | Main.parent,
|
---|
| 280 | msg,
|
---|
| 281 | tr("Authentication Failed"),
|
---|
| 282 | JOptionPane.ERROR_MESSAGE,
|
---|
| 283 | ht("/ErrorMessages#AuthenticationFailed")
|
---|
| 284 | );
|
---|
| 285 | }
|
---|
| 286 |
|
---|
| 287 | /**
|
---|
[5266] | 288 | * Explains a {@link OsmApiException} which was thrown because accessing a protected
|
---|
[5584] | 289 | * resource was forbidden (HTTP 403).
|
---|
[2748] | 290 | *
|
---|
| 291 | * @param e the exception
|
---|
| 292 | */
|
---|
| 293 | public static void explainAuthorizationFailed(OsmApiException e) {
|
---|
[6070] | 294 |
|
---|
[5584] | 295 | Matcher m;
|
---|
| 296 | String msg;
|
---|
| 297 | String url = e.getAccessedUrl();
|
---|
[6920] | 298 | Pattern p = Pattern.compile("https?://.*/api/0.6/(node|way|relation)/(\\d+)/(\\d+)");
|
---|
[6070] | 299 |
|
---|
[5584] | 300 | // Special case for individual access to redacted versions
|
---|
| 301 | // See http://wiki.openstreetmap.org/wiki/Open_Database_License/Changes_in_the_API
|
---|
| 302 | if (url != null && (m = p.matcher(url)).matches()) {
|
---|
| 303 | String type = m.group(1);
|
---|
| 304 | String id = m.group(2);
|
---|
| 305 | String version = m.group(3);
|
---|
| 306 | // {1} is the translation of "node", "way" or "relation"
|
---|
| 307 | msg = tr("Access to redacted version ''{0}'' of {1} {2} is forbidden.",
|
---|
| 308 | version, tr(type), id);
|
---|
[6349] | 309 | } else if (OsmApi.isUsingOAuth()) {
|
---|
[5584] | 310 | msg = ExceptionUtil.explainFailedOAuthAuthorisation(e);
|
---|
| 311 | } else {
|
---|
| 312 | msg = ExceptionUtil.explainFailedAuthorisation(e);
|
---|
| 313 | }
|
---|
[6070] | 314 |
|
---|
[2748] | 315 | HelpAwareOptionPane.showOptionDialog(
|
---|
| 316 | Main.parent,
|
---|
[5584] | 317 | msg,
|
---|
[2748] | 318 | tr("Authorisation Failed"),
|
---|
| 319 | JOptionPane.ERROR_MESSAGE,
|
---|
[5584] | 320 | ht("/ErrorMessages#AuthorizationFailed")
|
---|
[2748] | 321 | );
|
---|
| 322 | }
|
---|
| 323 |
|
---|
| 324 | /**
|
---|
[5266] | 325 | * Explains a {@link OsmApiException} which was thrown because of a
|
---|
[3101] | 326 | * client timeout (HTTP 408)
|
---|
| 327 | *
|
---|
| 328 | * @param e the exception
|
---|
| 329 | */
|
---|
| 330 | public static void explainClientTimeout(OsmApiException e) {
|
---|
| 331 | HelpAwareOptionPane.showOptionDialog(
|
---|
| 332 | Main.parent,
|
---|
| 333 | ExceptionUtil.explainClientTimeout(e),
|
---|
| 334 | tr("Client Time Out"),
|
---|
| 335 | JOptionPane.ERROR_MESSAGE,
|
---|
| 336 | ht("/ErrorMessages#ClientTimeOut")
|
---|
| 337 | );
|
---|
| 338 | }
|
---|
| 339 |
|
---|
| 340 | /**
|
---|
[5266] | 341 | * Explains a {@link OsmApiException} which was thrown because of a
|
---|
[4540] | 342 | * bandwidth limit (HTTP 509)
|
---|
| 343 | *
|
---|
| 344 | * @param e the exception
|
---|
| 345 | */
|
---|
| 346 | public static void explainBandwidthLimitExceeded(OsmApiException e) {
|
---|
| 347 | HelpAwareOptionPane.showOptionDialog(
|
---|
| 348 | Main.parent,
|
---|
| 349 | ExceptionUtil.explainBandwidthLimitExceeded(e),
|
---|
| 350 | tr("Bandwidth Limit Exceeded"),
|
---|
| 351 | JOptionPane.ERROR_MESSAGE,
|
---|
| 352 | ht("/ErrorMessages#BandwidthLimit")
|
---|
| 353 | );
|
---|
| 354 | }
|
---|
| 355 |
|
---|
| 356 | /**
|
---|
[9474] | 357 | * Explains a {@link OsmApiException} with a generic error message.
|
---|
[3101] | 358 | *
|
---|
| 359 | * @param e the exception
|
---|
| 360 | */
|
---|
| 361 | public static void explainGenericHttpException(OsmApiException e) {
|
---|
| 362 | HelpAwareOptionPane.showOptionDialog(
|
---|
| 363 | Main.parent,
|
---|
[11984] | 364 | ExceptionUtil.explainGeneric(e),
|
---|
[3101] | 365 | tr("Communication with OSM server failed"),
|
---|
| 366 | JOptionPane.ERROR_MESSAGE,
|
---|
| 367 | ht("/ErrorMessages#GenericCommunicationError")
|
---|
| 368 | );
|
---|
| 369 | }
|
---|
| 370 |
|
---|
| 371 | /**
|
---|
[5266] | 372 | * Explains a {@link OsmApiException} which was thrown because accessing a protected
|
---|
[2862] | 373 | * resource was forbidden.
|
---|
| 374 | *
|
---|
| 375 | * @param e the exception
|
---|
| 376 | */
|
---|
| 377 | public static void explainMissingOAuthAccessTokenException(MissingOAuthAccessTokenException e) {
|
---|
| 378 | HelpAwareOptionPane.showOptionDialog(
|
---|
| 379 | Main.parent,
|
---|
| 380 | ExceptionUtil.explainMissingOAuthAccessTokenException(e),
|
---|
[2895] | 381 | tr("Authentication failed"),
|
---|
[2862] | 382 | JOptionPane.ERROR_MESSAGE,
|
---|
| 383 | ht("/ErrorMessages#MissingOAuthAccessToken")
|
---|
| 384 | );
|
---|
| 385 | }
|
---|
| 386 |
|
---|
| 387 | /**
|
---|
[5266] | 388 | * Explains a {@link UnknownHostException} which has caused an {@link OsmTransferException}.
|
---|
[2512] | 389 | * This is most likely happening when there is an error in the API URL or when
|
---|
| 390 | * local DNS services are not working.
|
---|
| 391 | *
|
---|
| 392 | * @param e the exception
|
---|
| 393 | */
|
---|
| 394 | public static void explainNestedUnkonwnHostException(OsmTransferException e) {
|
---|
| 395 | HelpAwareOptionPane.showOptionDialog(
|
---|
| 396 | Main.parent,
|
---|
[3255] | 397 | ExceptionUtil.explainNestedUnknownHostException(e),
|
---|
[2512] | 398 | tr("Unknown host"),
|
---|
| 399 | JOptionPane.ERROR_MESSAGE,
|
---|
| 400 | ht("/ErrorMessages#UnknownHost")
|
---|
| 401 | );
|
---|
| 402 | }
|
---|
| 403 |
|
---|
| 404 | /**
|
---|
[5266] | 405 | * Explains an {@link OsmTransferException} to the user.
|
---|
[2512] | 406 | *
|
---|
[5266] | 407 | * @param e the {@link OsmTransferException}
|
---|
[2512] | 408 | */
|
---|
| 409 | public static void explainOsmTransferException(OsmTransferException e) {
|
---|
[8470] | 410 | if (ExceptionUtil.getNestedException(e, SecurityException.class) != null) {
|
---|
[2512] | 411 | explainSecurityException(e);
|
---|
| 412 | return;
|
---|
| 413 | }
|
---|
[8470] | 414 | if (ExceptionUtil.getNestedException(e, SocketException.class) != null) {
|
---|
[2512] | 415 | explainNestedSocketException(e);
|
---|
| 416 | return;
|
---|
| 417 | }
|
---|
[8470] | 418 | if (ExceptionUtil.getNestedException(e, UnknownHostException.class) != null) {
|
---|
[2512] | 419 | explainNestedUnkonwnHostException(e);
|
---|
| 420 | return;
|
---|
| 421 | }
|
---|
[8470] | 422 | if (ExceptionUtil.getNestedException(e, IOException.class) != null) {
|
---|
[2512] | 423 | explainNestedIOException(e);
|
---|
| 424 | return;
|
---|
| 425 | }
|
---|
[8470] | 426 | if (ExceptionUtil.getNestedException(e, IllegalDataException.class) != null) {
|
---|
[3069] | 427 | explainNestedIllegalDataException(e);
|
---|
| 428 | return;
|
---|
| 429 | }
|
---|
[8470] | 430 | if (ExceptionUtil.getNestedException(e, OfflineAccessException.class) != null) {
|
---|
[7434] | 431 | explainNestedOfflineAccessException(e);
|
---|
| 432 | return;
|
---|
| 433 | }
|
---|
[2512] | 434 | if (e instanceof OsmApiInitializationException) {
|
---|
| 435 | explainOsmApiInitializationException((OsmApiInitializationException) e);
|
---|
| 436 | return;
|
---|
| 437 | }
|
---|
| 438 |
|
---|
| 439 | if (e instanceof ChangesetClosedException) {
|
---|
[8510] | 440 | explainChangesetClosedException((ChangesetClosedException) e);
|
---|
[2512] | 441 | return;
|
---|
| 442 | }
|
---|
| 443 |
|
---|
[2862] | 444 | if (e instanceof MissingOAuthAccessTokenException) {
|
---|
[8510] | 445 | explainMissingOAuthAccessTokenException((MissingOAuthAccessTokenException) e);
|
---|
[2862] | 446 | return;
|
---|
| 447 | }
|
---|
| 448 |
|
---|
[2512] | 449 | if (e instanceof OsmApiException) {
|
---|
| 450 | OsmApiException oae = (OsmApiException) e;
|
---|
[2748] | 451 | switch(oae.getResponseCode()) {
|
---|
| 452 | case HttpURLConnection.HTTP_PRECON_FAILED:
|
---|
[2512] | 453 | explainPreconditionFailed(oae);
|
---|
| 454 | return;
|
---|
[2748] | 455 | case HttpURLConnection.HTTP_GONE:
|
---|
[2512] | 456 | explainGoneForUnknownPrimitive(oae);
|
---|
| 457 | return;
|
---|
[2748] | 458 | case HttpURLConnection.HTTP_INTERNAL_ERROR:
|
---|
[2512] | 459 | explainInternalServerError(oae);
|
---|
| 460 | return;
|
---|
[2748] | 461 | case HttpURLConnection.HTTP_BAD_REQUEST:
|
---|
[2512] | 462 | explainBadRequest(oae);
|
---|
| 463 | return;
|
---|
[2748] | 464 | case HttpURLConnection.HTTP_NOT_FOUND:
|
---|
[2512] | 465 | explainNotFound(oae);
|
---|
| 466 | return;
|
---|
[2748] | 467 | case HttpURLConnection.HTTP_CONFLICT:
|
---|
[2512] | 468 | explainConflict(oae);
|
---|
| 469 | return;
|
---|
[2748] | 470 | case HttpURLConnection.HTTP_UNAUTHORIZED:
|
---|
| 471 | explainAuthenticationFailed(oae);
|
---|
| 472 | return;
|
---|
| 473 | case HttpURLConnection.HTTP_FORBIDDEN:
|
---|
| 474 | explainAuthorizationFailed(oae);
|
---|
| 475 | return;
|
---|
[3101] | 476 | case HttpURLConnection.HTTP_CLIENT_TIMEOUT:
|
---|
| 477 | explainClientTimeout(oae);
|
---|
| 478 | return;
|
---|
[11984] | 479 | case 509: case 429:
|
---|
[4540] | 480 | explainBandwidthLimitExceeded(oae);
|
---|
| 481 | return;
|
---|
[3101] | 482 | default:
|
---|
| 483 | explainGenericHttpException(oae);
|
---|
| 484 | return;
|
---|
[2512] | 485 | }
|
---|
| 486 | }
|
---|
[2862] | 487 | explainGeneric(e);
|
---|
[2512] | 488 | }
|
---|
| 489 |
|
---|
| 490 | /**
|
---|
| 491 | * explains the case of an error due to a delete request on an already deleted
|
---|
[5266] | 492 | * {@link OsmPrimitive}, i.e. a HTTP response code 410, where we don't know which
|
---|
| 493 | * {@link OsmPrimitive} is causing the error.
|
---|
[2512] | 494 | *
|
---|
| 495 | * @param e the exception
|
---|
| 496 | */
|
---|
| 497 | public static void explainGoneForUnknownPrimitive(OsmApiException e) {
|
---|
| 498 | HelpAwareOptionPane.showOptionDialog(
|
---|
| 499 | Main.parent,
|
---|
| 500 | ExceptionUtil.explainGoneForUnknownPrimitive(e),
|
---|
| 501 | tr("Object deleted"),
|
---|
| 502 | JOptionPane.ERROR_MESSAGE,
|
---|
| 503 | ht("/ErrorMessages#GoneForUnknownPrimitive")
|
---|
| 504 | );
|
---|
| 505 | }
|
---|
| 506 |
|
---|
| 507 | /**
|
---|
[5266] | 508 | * Explains an {@link Exception} to the user.
|
---|
[2512] | 509 | *
|
---|
[5266] | 510 | * @param e the {@link Exception}
|
---|
[2512] | 511 | */
|
---|
| 512 | public static void explainException(Exception e) {
|
---|
[8470] | 513 | if (ExceptionUtil.getNestedException(e, InvocationTargetException.class) != null) {
|
---|
[2512] | 514 | explainNestedInvocationTargetException(e);
|
---|
| 515 | return;
|
---|
| 516 | }
|
---|
| 517 | if (e instanceof OsmTransferException) {
|
---|
| 518 | explainOsmTransferException((OsmTransferException) e);
|
---|
| 519 | return;
|
---|
| 520 | }
|
---|
| 521 | explainGeneric(e);
|
---|
| 522 | }
|
---|
| 523 | }
|
---|