Changeset 9474 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2016-01-16T00:00:30+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/ExceptionDialogUtil.java
r8510 r9474 354 354 355 355 /** 356 * Explains a {@link OsmApiException} with a generic error 357 * message. 356 * Explains a {@link OsmApiException} with a generic error message. 358 357 * 359 358 * @param e the exception … … 392 391 * @param e the exception 393 392 */ 394 395 393 public static void explainNestedUnkonwnHostException(OsmTransferException e) { 396 394 HelpAwareOptionPane.showOptionDialog( -
trunk/src/org/openstreetmap/josm/tools/ExceptionUtil.java
r9353 r9474 36 36 import org.openstreetmap.josm.tools.date.DateUtils; 37 37 38 /** 39 * Utilities for exception handling. 40 * @since 2097 41 */ 38 42 public final class ExceptionUtil { 39 43 … … 43 47 44 48 /** 45 * handles an exception caught during OSM API initialization49 * Explains an exception caught during OSM API initialization. 46 50 * 47 51 * @param e the exception … … 53 57 "<html>Failed to initialize communication with the OSM server {0}.<br>" 54 58 + "Check the server URL in your preferences and your internet connection.", 55 OsmApi.getOsmApi().getServerUrl()); 56 } 57 59 OsmApi.getOsmApi().getServerUrl())+"</html>"; 60 } 61 62 /** 63 * Explains a {@link OsmApiException} which was thrown because accessing a protected 64 * resource was forbidden. 65 * 66 * @param e the exception 67 * @return The HTML formatted error message to display 68 */ 58 69 public static String explainMissingOAuthAccessTokenException(MissingOAuthAccessTokenException e) { 59 70 Main.error(e); … … 69 80 70 81 public static Pair<OsmPrimitive, Collection<OsmPrimitive>> parsePreconditionFailed(String msg) { 82 if (msg == null) 83 return null; 71 84 final String ids = "(\\d+(?:,\\d+)*)"; 72 85 final Collection<OsmPrimitive> refs = new TreeSet<>(); // error message can contain several times the same way 73 86 Matcher m; 74 m = Pattern.compile(".*Node (\\d+) is still used by relations " + ids + ".*").matcher(msg);87 m = Pattern.compile(".*Node (\\d+) is still used by relations? " + ids + ".*").matcher(msg); 75 88 if (m.matches()) { 76 89 OsmPrimitive n = new Node(Long.parseLong(m.group(1))); … … 80 93 return Pair.create(n, refs); 81 94 } 82 m = Pattern.compile(".*Node (\\d+) is still used by ways " + ids + ".*").matcher(msg);95 m = Pattern.compile(".*Node (\\d+) is still used by ways? " + ids + ".*").matcher(msg); 83 96 if (m.matches()) { 84 97 OsmPrimitive n = new Node(Long.parseLong(m.group(1))); … … 96 109 return Pair.create(n, refs); 97 110 } 98 m = Pattern.compile(".*Way (\\d+) is still used by relations " + ids + ".*").matcher(msg);111 m = Pattern.compile(".*Way (\\d+) is still used by relations? " + ids + ".*").matcher(msg); 99 112 if (m.matches()) { 100 113 OsmPrimitive n = new Way(Long.parseLong(m.group(1))); … … 240 253 } 241 254 255 /** 256 * Explains a {@link OsmApiException} which was thrown because the authentication at 257 * the OSM server failed, with basic authentication. 258 * 259 * @param e the exception 260 * @return The HTML formatted error message to display 261 */ 242 262 public static String explainFailedBasicAuthentication(OsmApiException e) { 243 263 Main.error(e); … … 250 270 } 251 271 272 /** 273 * Explains a {@link OsmApiException} which was thrown because the authentication at 274 * the OSM server failed, with OAuth authentication. 275 * 276 * @param e the exception 277 * @return The HTML formatted error message to display 278 */ 252 279 public static String explainFailedOAuthAuthentication(OsmApiException e) { 253 280 Main.error(e); … … 260 287 } 261 288 289 /** 290 * Explains a {@link OsmApiException} which was thrown because accessing a protected 291 * resource was forbidden (HTTP 403), without OAuth authentication. 292 * 293 * @param e the exception 294 * @return The HTML formatted error message to display 295 */ 262 296 public static String explainFailedAuthorisation(OsmApiException e) { 263 297 Main.error(e); 264 298 String header = e.getErrorHeader(); 265 299 String body = e.getErrorBody(); 266 String msg = null;300 String msg; 267 301 if (header != null) { 268 302 if (body != null && !header.equals(body)) { … … 291 325 } 292 326 327 /** 328 * Explains a {@link OsmApiException} which was thrown because accessing a protected 329 * resource was forbidden (HTTP 403), with OAuth authentication. 330 * 331 * @param e the exception 332 * @return The HTML formatted error message to display 333 */ 293 334 public static String explainFailedOAuthAuthorisation(OsmApiException e) { 294 335 Main.error(e); … … 356 397 String msg = e.getErrorHeader(); 357 398 if (msg != null) { 358 String pattern = "The changeset (\\d+) was closed at (.*)"; 359 Pattern p = Pattern.compile(pattern); 360 Matcher m = p.matcher(msg); 399 Matcher m = Pattern.compile("The changeset (\\d+) was closed at (.*)").matcher(msg); 361 400 if (m.matches()) { 362 401 long changesetId = Long.parseLong(m.group(1)); … … 392 431 "<html>The server reported that it has detected a conflict."); 393 432 } 394 return msg ;433 return msg.endsWith("</html>") ? msg : (msg + "</html>"); 395 434 } 396 435 … … 449 488 return tr("<html>Failed to open a connection to the remote server<br>" + "''{0}''<br>" 450 489 + "for security reasons. This is most likely because you are running<br>" 451 + "in an applet and because you did not load your applet from ''{1}''.", apiUrl, host) ;490 + "in an applet and because you did not load your applet from ''{1}''.", apiUrl, host)+"</html>"; 452 491 } 453 492 … … 463 502 Main.error(e); 464 503 return tr("<html>Failed to open a connection to the remote server<br>" + "''{0}''.<br>" 465 + "Please check your internet connection.", e.getUrl()) ;504 + "Please check your internet connection.", e.getUrl())+"</html>"; 466 505 } 467 506 … … 479 518 return tr("<html>Failed to upload data to or download data from<br>" + "''{0}''<br>" 480 519 + "due to a problem with transferring data.<br>" 481 + "Details (untranslated): {1}</html>", e.getUrl(), ioe482 .getMessage());520 + "Details (untranslated): {1}</html>", e.getUrl(), 521 ioe != null ? ioe.getMessage() : "null"); 483 522 } 484 523 … … 495 534 return tr("<html>Failed to download data. " 496 535 + "Its format is either unsupported, ill-formed, and/or inconsistent.<br>" 497 + "<br>Details (untranslated): {0}</html>", ide .getMessage());536 + "<br>Details (untranslated): {0}</html>", ide != null ? ide.getMessage() : "null"); 498 537 } 499 538 … … 510 549 Main.error(e); 511 550 return tr("<html>Failed to download data.<br>" 512 + "<br>Details: {0}</html>", oae .getMessage());551 + "<br>Details: {0}</html>", oae != null ? oae.getMessage() : "null"); 513 552 } 514 553 515 554 /** 516 555 * Explains a {@link OsmApiException} which was thrown because of an internal server 517 * error in the OSM API server. .556 * error in the OSM API server. 518 557 * 519 558 * @param e the exception … … 523 562 Main.error(e); 524 563 return tr("<html>The OSM server<br>" + "''{0}''<br>" + "reported an internal server error.<br>" 525 + "This is most likely a temporary problem. Please try again later.", e.getUrl()) ;564 + "This is most likely a temporary problem. Please try again later.", e.getUrl())+"</html>"; 526 565 } 527 566 … … 613 652 return tr("<html>Failed to open a connection to the remote server<br>" + "''{0}''.<br>" 614 653 + "Host name ''{1}'' could not be resolved. <br>" 615 + "Please check the API URL in your preferences and your internet connection.", apiUrl, host) ;654 + "Please check the API URL in your preferences and your internet connection.", apiUrl, host)+"</html>"; 616 655 } 617 656 … … 708 747 } 709 748 } 710 711 749 }
Note:
See TracChangeset
for help on using the changeset viewer.