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

see #17722 - proper notification of user block

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.