- Timestamp:
- 2019-05-18T16:29:09+02:00 (6 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/ExceptionDialogUtil.java
r14810 r15084 286 286 msg = tr("Access to redacted version ''{0}'' of {1} {2} is forbidden.", 287 287 version, tr(type), id); 288 } else if (OsmApi.isUsingOAuth() ) {288 } else if (OsmApi.isUsingOAuth() && !ExceptionUtil.isUserBlocked(e)) { 289 289 msg = ExceptionUtil.explainFailedOAuthAuthorisation(e); 290 290 } else { -
trunk/src/org/openstreetmap/josm/io/MessageNotifier.java
r14326 r15084 14 14 import org.openstreetmap.josm.data.preferences.BooleanProperty; 15 15 import org.openstreetmap.josm.data.preferences.IntegerProperty; 16 import org.openstreetmap.josm.gui.ExceptionDialogUtil; 16 17 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 17 18 import org.openstreetmap.josm.io.auth.CredentialsAgentException; … … 89 90 } 90 91 } catch (OsmTransferException e) { 91 Logging.warn(e);92 ExceptionDialogUtil.explainOsmTransferException(e); 92 93 } 93 94 } -
trunk/src/org/openstreetmap/josm/io/OsmApiException.java
r15077 r15084 213 213 public String getDisplayMessage() { 214 214 StringBuilder sb = new StringBuilder(); 215 if (errorHeader != null) { 216 sb.append(tr(errorHeader)); 217 sb.append(tr("(Code={0})", responseCode)); 218 } else if (errorBody != null && !errorBody.trim().isEmpty()) { 219 errorBody = errorBody.trim(); 220 sb.append(tr(errorBody)); 221 sb.append(tr("(Code={0})", responseCode)); 215 String header = Utils.strip(errorHeader); 216 String body = Utils.strip(errorBody); 217 if ((header == null || header.isEmpty()) && (body == null || body.isEmpty())) { 218 sb.append(tr("The server replied an error with code {0}.", responseCode)); 222 219 } else { 223 sb.append(tr("The server replied an error with code {0}.", responseCode)); 220 if (header != null && !header.isEmpty()) { 221 sb.append(tr(header)); 222 } 223 if (body != null && !body.isEmpty()) { 224 if (sb.length() > 0) { 225 sb.append(". "); 226 } 227 sb.append(tr(body)); 228 } 229 sb.append(' ').append(tr("(Code={0})", responseCode)); 224 230 } 225 231 return sb.toString(); -
trunk/src/org/openstreetmap/josm/tools/ExceptionUtil.java
r12992 r15084 2 2 package org.openstreetmap.josm.tools; 3 3 4 import static org.openstreetmap.josm.tools.I18n.marktr; 4 5 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import static org.openstreetmap.josm.tools.I18n.trn; … … 43 44 public final class ExceptionUtil { 44 45 46 /** 47 * Error message sent by the OSM API when a user has been blocked. 48 */ 49 private static final String OSM_API_BLOCKED = 50 marktr("Your access to the API has been blocked. Please log-in to the web interface to find out more."); 51 45 52 private ExceptionUtil() { 46 53 // Hide default constructor for utils classes … … 296 303 public static String explainFailedAuthorisation(OsmApiException e) { 297 304 Logging.error(e); 298 String header = e.getErrorHeader(); 299 String body = e.getErrorBody(); 300 String msg; 301 if (header != null) { 302 if (body != null && !header.equals(body)) { 303 msg = header + " (" + body + ')'; 304 } else { 305 msg = header; 306 } 307 } else { 308 msg = body; 309 } 305 String msg = e.getDisplayMessage(); 310 306 311 307 if (msg != null && !msg.isEmpty()) { … … 726 722 } 727 723 724 /** 725 * Determines if the OSM API exception has been thrown because user has been blocked. 726 * @param e OSM API exception 727 * @return {@code true} if the OSM API exception has been thrown because user has been blocked 728 * @since 15084 729 */ 730 public static boolean isUserBlocked(OsmApiException e) { 731 return OSM_API_BLOCKED.equals(e.getErrorHeader()); 732 } 733 728 734 static String getUrlFromException(OsmApiException e) { 729 735 if (e.getAccessedUrl() != null) { -
trunk/test/unit/org/openstreetmap/josm/tools/ExceptionUtilTest.java
r13812 r15084 11 11 import java.util.TimeZone; 12 12 13 import org.junit.BeforeClass; 13 import org.junit.Before; 14 import org.junit.Rule; 14 15 import org.junit.Test; 15 import org.openstreetmap.josm.JOSMFixture;16 16 import org.openstreetmap.josm.io.ChangesetClosedException; 17 17 import org.openstreetmap.josm.io.IllegalDataException; … … 22 22 import org.openstreetmap.josm.io.OsmApiInitializationException; 23 23 import org.openstreetmap.josm.io.auth.CredentialsManager; 24 import org.openstreetmap.josm.testutils.JOSMTestRules; 24 25 import org.openstreetmap.josm.tools.date.DateUtils; 25 26 import org.openstreetmap.josm.tools.date.DateUtilsTest; 27 28 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 26 29 27 30 /** … … 30 33 public class ExceptionUtilTest { 31 34 35 /** 36 * Setup rule. 37 */ 38 @Rule 39 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 40 public JOSMTestRules test = new JOSMTestRules().preferences().fakeAPI(); 41 32 42 private static String baseUrl; 33 43 private static String serverUrl; … … 39 49 * @throws Exception in case of error 40 50 */ 41 @BeforeClass 42 public static void setUp() throws Exception { 43 JOSMFixture.createUnitTestFixture().init(); 51 @Before 52 public void setUp() throws Exception { 44 53 OsmApi api = OsmApi.getOsmApi(); 45 api.initialize(null);46 54 baseUrl = api.getBaseUrl(); 47 55 serverUrl = api.getServerUrl(); … … 154 162 @Test 155 163 public void testExplainFailedAuthorisation() { 156 assertEquals("<html>Authorisation at the OSM server failed.<br></html>", 164 assertEquals("<html>Authorisation at the OSM server failed.<br>The server reported the following error:<br>"+ 165 "'The server replied an error with code 0.'</html>", 157 166 ExceptionUtil.explainFailedAuthorisation(new OsmApiException(""))); 158 assertEquals("<html>Authorisation at the OSM server failed.<br>The server reported the following error:<br>'header '</html>",167 assertEquals("<html>Authorisation at the OSM server failed.<br>The server reported the following error:<br>'header (Code=403)'</html>", 159 168 ExceptionUtil.explainFailedAuthorisation(new OsmApiException(HttpURLConnection.HTTP_FORBIDDEN, "header", null))); 160 assertEquals("<html>Authorisation at the OSM server failed.<br>The server reported the following error:<br>'header (body)'</html>",169 assertEquals("<html>Authorisation at the OSM server failed.<br>The server reported the following error:<br>'header. body (Code=403)'</html>", 161 170 ExceptionUtil.explainFailedAuthorisation(new OsmApiException(HttpURLConnection.HTTP_FORBIDDEN, "header", "body"))); 162 assertEquals("<html>Authorisation at the OSM server failed.<br>The server reported the following error:<br>'body '</html>",171 assertEquals("<html>Authorisation at the OSM server failed.<br>The server reported the following error:<br>'body (Code=403)'</html>", 163 172 ExceptionUtil.explainFailedAuthorisation(new OsmApiException(HttpURLConnection.HTTP_FORBIDDEN, null, "body"))); 164 173 } … … 247 256 @Test 248 257 public void testExplainMissingOAuthAccessTokenException() { 249 assertEquals("<html>Failed to authenticate at the OSM server 'http s://api06.dev.openstreetmap.org/api'.<br>"+258 assertEquals("<html>Failed to authenticate at the OSM server 'http://fake.xxx/api'.<br>"+ 250 259 "You are using OAuth to authenticate but currently there is no<br>OAuth Access Token configured.<br>"+ 251 260 "Please open the Preferences Dialog and generate or enter an Access Token.</html>",
Note:
See TracChangeset
for help on using the changeset viewer.