/** * Explains a {@link OsmApiException} which was thrown because accessing a protected resource was * forbidden (HTTP 403). * * @param e the exception */ public static void explainAuthorizationFailed(OsmApiException e) { Matcher m; String msg; String url = e.getAccessedUrl(); Pattern p = Pattern.compile("https?://.*/api/0.6/(node|way|relation)/(\\d+)/(\\d+)"); // Special case for individual access to redacted versions // See http://wiki.openstreetmap.org/wiki/Open_Database_License/Changes_in_the_API if (url != null && (m = p.matcher(url)).matches()) { String type = m.group(1); String id = m.group(2); String version = m.group(3); // {1} is the translation of "node", "way" or "relation" msg = tr("Access to redacted version ''{0}'' of {1} {2} is forbidden.", version, tr(type), id); } else if (OsmApi.isUsingOAuth()) { msg = ExceptionUtil.explainFailedOAuthAuthorisation(e); } else { msg = ExceptionUtil.explainFailedAuthorisation(e); } HelpAwareOptionPane.showOptionDialog( Main.parent, msg, tr("Authorisation Failed"), JOptionPane.ERROR_MESSAGE, ht("/ErrorMessages#AuthorizationFailed")); }
/** * Explains an {@link OsmTransferException} to the user. * * @param e the {@link OsmTransferException} */ public static void explainOsmTransferException(OsmTransferException e) { if (getNestedException(e, SecurityException.class) != null) { explainSecurityException(e); return; } if (getNestedException(e, SocketException.class) != null) { explainNestedSocketException(e); return; } if (getNestedException(e, UnknownHostException.class) != null) { explainNestedUnkonwnHostException(e); return; } if (getNestedException(e, IOException.class) != null) { explainNestedIOException(e); return; } if (getNestedException(e, IllegalDataException.class) != null) { explainNestedIllegalDataException(e); return; } if (e instanceof OsmApiInitializationException) { explainOsmApiInitializationException((OsmApiInitializationException) e); return; } if (e instanceof ChangesetClosedException) { explainChangesetClosedException((ChangesetClosedException) e); return; } if (e instanceof MissingOAuthAccessTokenException) { explainMissingOAuthAccessTokenException((MissingOAuthAccessTokenException) e); return; } if (e instanceof OsmApiException) { OsmApiException oae = (OsmApiException) e; switch (oae.getResponseCode()) { case HttpURLConnection.HTTP_PRECON_FAILED: explainPreconditionFailed(oae); return; case HttpURLConnection.HTTP_GONE: explainGoneForUnknownPrimitive(oae); return; case HttpURLConnection.HTTP_INTERNAL_ERROR: explainInternalServerError(oae); return; case HttpURLConnection.HTTP_BAD_REQUEST: explainBadRequest(oae); return; case HttpURLConnection.HTTP_NOT_FOUND: explainNotFound(oae); return; case HttpURLConnection.HTTP_CONFLICT: explainConflict(oae); return; case HttpURLConnection.HTTP_UNAUTHORIZED: explainAuthenticationFailed(oae); return; case HttpURLConnection.HTTP_FORBIDDEN: explainAuthorizationFailed(oae); return; case HttpURLConnection.HTTP_CLIENT_TIMEOUT: explainClientTimeout(oae); return; case 509: explainBandwidthLimitExceeded(oae); return; default: explainGenericHttpException(oae); return; } } explainGeneric(e); }