Changeset 15084 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2019-05-18T16:29:09+02:00 (5 years ago)
Author:
Don-vip
Message:

see #17722 - proper notification of user block

Location:
trunk/src/org/openstreetmap/josm
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/ExceptionDialogUtil.java

    r14810 r15084  
    286286            msg = tr("Access to redacted version ''{0}'' of {1} {2} is forbidden.",
    287287                    version, tr(type), id);
    288         } else if (OsmApi.isUsingOAuth()) {
     288        } else if (OsmApi.isUsingOAuth() && !ExceptionUtil.isUserBlocked(e)) {
    289289            msg = ExceptionUtil.explainFailedOAuthAuthorisation(e);
    290290        } else {
  • trunk/src/org/openstreetmap/josm/io/MessageNotifier.java

    r14326 r15084  
    1414import org.openstreetmap.josm.data.preferences.BooleanProperty;
    1515import org.openstreetmap.josm.data.preferences.IntegerProperty;
     16import org.openstreetmap.josm.gui.ExceptionDialogUtil;
    1617import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    1718import org.openstreetmap.josm.io.auth.CredentialsAgentException;
     
    8990                }
    9091            } catch (OsmTransferException e) {
    91                 Logging.warn(e);
     92                ExceptionDialogUtil.explainOsmTransferException(e);
    9293            }
    9394        }
  • trunk/src/org/openstreetmap/josm/io/OsmApiException.java

    r15077 r15084  
    213213    public String getDisplayMessage() {
    214214        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));
    222219        } 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));
    224230        }
    225231        return sb.toString();
  • trunk/src/org/openstreetmap/josm/tools/ExceptionUtil.java

    r12992 r15084  
    22package org.openstreetmap.josm.tools;
    33
     4import static org.openstreetmap.josm.tools.I18n.marktr;
    45import static org.openstreetmap.josm.tools.I18n.tr;
    56import static org.openstreetmap.josm.tools.I18n.trn;
     
    4344public final class ExceptionUtil {
    4445
     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
    4552    private ExceptionUtil() {
    4653        // Hide default constructor for utils classes
     
    296303    public static String explainFailedAuthorisation(OsmApiException e) {
    297304        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();
    310306
    311307        if (msg != null && !msg.isEmpty()) {
     
    726722    }
    727723
     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
    728734    static String getUrlFromException(OsmApiException e) {
    729735        if (e.getAccessedUrl() != null) {
Note: See TracChangeset for help on using the changeset viewer.