Changeset 5584 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2012-11-17T14:08:43+01:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/ExceptionDialogUtil.java
r5275 r5584 10 10 import java.net.SocketException; 11 11 import java.net.UnknownHostException; 12 import java.util.regex.Matcher; 13 import java.util.regex.Pattern; 12 14 13 15 import javax.swing.JOptionPane; … … 242 244 } 243 245 246 private static boolean isOAuth() { 247 return Main.pref.get("osm-server.auth-method", "basic").equals("oauth"); 248 } 249 244 250 /** 245 251 * Explains a {@link OsmApiException} which was thrown because the authentication at … … 249 255 */ 250 256 public static void explainAuthenticationFailed(OsmApiException e) { 251 String authMethod = Main.pref.get("osm-server.auth-method", "basic");252 257 String msg; 253 if ( authMethod.equals("oauth")) {258 if (isOAuth()) { 254 259 msg = ExceptionUtil.explainFailedOAuthAuthentication(e); 255 260 } else { … … 268 273 /** 269 274 * Explains a {@link OsmApiException} which was thrown because accessing a protected 270 * resource was forbidden .275 * resource was forbidden (HTTP 403). 271 276 * 272 277 * @param e the exception 273 278 */ 274 279 public static void explainAuthorizationFailed(OsmApiException e) { 275 // Fixme: add special handling that calls ExceptionUtil.explainFailedOAuthAuthorisation(e) 276 HelpAwareOptionPane.showOptionDialog( 277 Main.parent, 278 ExceptionUtil.explainFailedAuthorisation(e), 280 281 Matcher m; 282 String msg; 283 String url = e.getAccessedUrl(); 284 Pattern p = Pattern.compile("http://.*/api/0.6/(node|way|relation)/(\\d+)/(\\d+)"); 285 286 // Special case for individual access to redacted versions 287 // See http://wiki.openstreetmap.org/wiki/Open_Database_License/Changes_in_the_API 288 if (url != null && (m = p.matcher(url)).matches()) { 289 String type = m.group(1); 290 String id = m.group(2); 291 String version = m.group(3); 292 // {1} is the translation of "node", "way" or "relation" 293 msg = tr("Access to redacted version ''{0}'' of {1} {2} is forbidden.", 294 version, tr(type), id); 295 } else if (isOAuth()) { 296 msg = ExceptionUtil.explainFailedOAuthAuthorisation(e); 297 } else { 298 msg = ExceptionUtil.explainFailedAuthorisation(e); 299 } 300 301 HelpAwareOptionPane.showOptionDialog( 302 Main.parent, 303 msg, 279 304 tr("Authorisation Failed"), 280 305 JOptionPane.ERROR_MESSAGE, 281 ht("/ErrorMessages#Auth enticationFailed")306 ht("/ErrorMessages#AuthorizationFailed") 282 307 ); 283 308 } -
trunk/src/org/openstreetmap/josm/io/OsmApiException.java
r5386 r5584 14 14 private String accessedUrl; 15 15 16 /** 17 * Constructs an {@code OsmApiException} with the specified response code, error header and error body 18 * @param responseCode The HTTP response code replied by the OSM server. See {@link java.net.HttpURLConnection HttpURLConnection} for predefined HTTP response code values 19 * @param errorHeader The error header, as transmitted in the {@code Error} field of the HTTP response header 20 * @param errorBody The error body, as transmitted in the HTTP response body 21 * @param accessedUrl The complete URL accessed when this error occured 22 * @since 5584 23 */ 24 public OsmApiException(int responseCode, String errorHeader, String errorBody, String accessedUrl) { 25 this.responseCode = responseCode; 26 this.errorHeader = errorHeader; 27 this.errorBody = errorBody; 28 this.accessedUrl = accessedUrl; 29 } 30 16 31 /** 17 32 * Constructs an {@code OsmApiException} with the specified response code, error header and error body -
trunk/src/org/openstreetmap/josm/io/OsmServerReader.java
r5575 r5584 122 122 } 123 123 124 throw new OsmApiException(activeConnection.getResponseCode(), errorHeader, errorBody.toString() );124 throw new OsmApiException(activeConnection.getResponseCode(), errorHeader, errorBody.toString(), url.toString()); 125 125 } 126 126 … … 131 131 else 132 132 throw new OsmTransferException(e); 133 134 133 } 135 134 } finally { -
trunk/src/org/openstreetmap/josm/tools/ExceptionUtil.java
r5525 r5584 17 17 import java.util.Date; 18 18 import java.util.Locale; 19 import java.util.Set;20 19 import java.util.TreeSet; 21 20 import java.util.regex.Matcher; … … 270 269 String header = e.getErrorHeader(); 271 270 String body = e.getErrorBody(); 272 if (body.equals("Your access to the API is temporarily suspended. Please log-in to the web interface to view the Contributor Terms. You do not need to agree, but you must view them.")) {273 return tr("<html>"274 +"Your access to the API is temporarily suspended.<br>"275 + "Please log-in to the web interface to view the Contributor Terms.<br>"276 + "You do not need to agree, but you must view them."277 + "</html>");278 }279 271 String msg = null; 280 272 if (header != null) { … … 288 280 } 289 281 290 return tr("<html>" 291 + "Authorisation at the OSM server failed.<br>" 292 + "The server reported the following error:<br>" 293 + "''{0}''" 294 + "</html>", 295 msg 296 ); 282 if (msg != null && !msg.isEmpty()) { 283 return tr("<html>" 284 + "Authorisation at the OSM server failed.<br>" 285 + "The server reported the following error:<br>" 286 + "''{0}''" 287 + "</html>", 288 msg 289 ); 290 } else { 291 return tr("<html>" 292 + "Authorisation at the OSM server failed.<br>" 293 + "</html>" 294 ); 295 } 297 296 } 298 297
Note:
See TracChangeset
for help on using the changeset viewer.