Changeset 9876 in josm


Ignore:
Timestamp:
2016-02-24T11:14:39+01:00 (8 years ago)
Author:
simon04
Message:

fix #12521 - On Overpass API error OSM API gets blamed

File:
1 edited

Legend:

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

    r9474 r9876  
    356356                + "Communication with the OSM server ''{0}'' timed out. Please retry later."
    357357                + "</html>",
    358                 OsmApi.getOsmApi().getBaseUrl()
     358                getUrlFromException(e)
    359359        );
    360360    }
     
    381381                + "<strong>Error message (untranslated)</strong>: {2}"
    382382                + "</html>",
    383                 OsmApi.getOsmApi().getBaseUrl(),
     383                getUrlFromException(e),
    384384                e.getResponseCode(),
    385385                errMsg
     
    572572     */
    573573    public static String explainBadRequest(OsmApiException e) {
    574         String url = null;
    575         if (e.getAccessedUrl() != null) {
    576             try {
    577                 url = new URL(e.getAccessedUrl()).getHost();
    578             } catch (MalformedURLException e1) {
    579                 Main.warn(e1);
    580             }
    581         }
    582         if (url == null && e.getUrl() != null) {
    583             url = e.getUrl();
    584         } else if (url == null) {
    585             url = OsmApi.getOsmApi().getBaseUrl();
    586         }
    587         String message = tr("The OSM server ''{0}'' reported a bad request.<br>", url);
     574        String message = tr("The OSM server ''{0}'' reported a bad request.<br>", getUrlFromException(e));
    588575        String errorHeader = e.getErrorHeader();
    589576        if (errorHeader != null && (errorHeader.startsWith("The maximum bbox") ||
     
    619606     */
    620607    public static String explainNotFound(OsmApiException e) {
    621         String apiUrl = OsmApi.getOsmApi().getBaseUrl();
    622608        String message = tr("The OSM server ''{0}'' does not know about an object<br>"
    623609                + "you tried to read, update, or delete. Either the respective object<br>"
    624610                + "does not exist on the server or you are using an invalid URL to access<br>"
    625611                + "it. Please carefully check the server''s address ''{0}'' for typos.",
    626                 apiUrl);
     612                getUrlFromException(e));
    627613        Main.error(e);
    628614        return "<html>" + message + "</html>";
     
    747733        }
    748734    }
     735
     736    static String getUrlFromException(OsmApiException e) {
     737        if (e.getAccessedUrl() != null) {
     738            try {
     739                return new URL(e.getAccessedUrl()).getHost();
     740            } catch (MalformedURLException e1) {
     741                Main.warn(e1);
     742            }
     743        }
     744        if (e.getUrl() != null) {
     745            return e.getUrl();
     746        } else {
     747            return OsmApi.getOsmApi().getBaseUrl();
     748        }
     749    }
    749750}
Note: See TracChangeset for help on using the changeset viewer.