Changeset 15089 in josm for trunk/src/org


Ignore:
Timestamp:
2019-05-18T18:36:22+02:00 (6 years ago)
Author:
Don-vip
Message:

fix #17722 - detect other block texts. Assume the API will always send Error header in English, and localized message in body

Texts taken from https://github.com/openstreetmap/openstreetmap-website/blob/8e258d810c8db6e5dccc84fb3292af0e5dd19642/config/locales/en.yml#L1845

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/ExceptionUtil.java

    r15084 r15089  
    22package org.openstreetmap.josm.tools;
    33
    4 import static org.openstreetmap.josm.tools.I18n.marktr;
    54import static org.openstreetmap.josm.tools.I18n.tr;
    65import static org.openstreetmap.josm.tools.I18n.trn;
     
    1413import java.text.DateFormat;
    1514import java.text.ParseException;
     15import java.util.Arrays;
    1616import java.util.Collection;
    1717import java.util.Date;
     18import java.util.List;
    1819import java.util.Objects;
    1920import java.util.Optional;
     
    4546
    4647    /**
    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.");
     48     * Error messages sent by the OSM API when a user has been blocked/suspended.
     49     */
     50    private static final List<String> OSM_API_BLOCK_MESSAGES = Arrays.asList(
     51            "You have an urgent message on the OpenStreetMap web site. " +
     52                    "You need to read the message before you will be able to save your edits.",
     53            "Your access to the API has been blocked. Please log-in to the web interface to find out more.",
     54            "Your access to the API is temporarily suspended. Please log-in to the web interface to view the Contributor Terms." +
     55                    " You do not need to agree, but you must view them.");
    5156
    5257    private ExceptionUtil() {
     
    723728
    724729    /**
    725      * Determines if the OSM API exception has been thrown because user has been blocked.
     730     * Determines if the OSM API exception has been thrown because user has been blocked or suspended.
    726731     * @param e OSM API exception
    727      * @return {@code true} if the OSM API exception has been thrown because user has been blocked
     732     * @return {@code true} if the OSM API exception has been thrown because user has been blocked or suspended
    728733     * @since 15084
    729734     */
    730735    public static boolean isUserBlocked(OsmApiException e) {
    731         return OSM_API_BLOCKED.equals(e.getErrorHeader());
     736        return OSM_API_BLOCK_MESSAGES.contains(e.getErrorHeader());
    732737    }
    733738
Note: See TracChangeset for help on using the changeset viewer.