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