Changeset 13499 in josm for trunk


Ignore:
Timestamp:
2018-03-04T16:09:51+01:00 (6 years ago)
Author:
Don-vip
Message:

fix #16050 - nicer display of HTTP errors from OSM API

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

Legend:

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

    r12620 r13499  
    1717import org.openstreetmap.josm.Main;
    1818import org.openstreetmap.josm.data.osm.OsmPrimitive;
     19import org.openstreetmap.josm.gui.widgets.HtmlPanel;
    1920import org.openstreetmap.josm.io.ChangesetClosedException;
    2021import org.openstreetmap.josm.io.IllegalDataException;
     
    361362     */
    362363    public static void explainGenericHttpException(OsmApiException e) {
    363         HelpAwareOptionPane.showOptionDialog(
    364                 Main.parent,
    365                 ExceptionUtil.explainGeneric(e),
     364        String body = e.getErrorBody();
     365        Object msg = null;
     366        if ("text/html".equals(e.getContentType()) && body != null && body.startsWith("<") && body.contains("<html>")) {
     367            msg = new HtmlPanel(body);
     368        } else {
     369            msg = ExceptionUtil.explainGeneric(e);
     370        }
     371        HelpAwareOptionPane.showOptionDialog(
     372                Main.parent,
     373                msg,
    366374                tr("Communication with OSM server failed"),
    367375                JOptionPane.ERROR_MESSAGE,
  • trunk/src/org/openstreetmap/josm/io/OsmApi.java

    r13488 r13499  
    727727                    CredentialsManager.getInstance().purgeCredentialsCache(RequestorType.SERVER);
    728728                    throw new OsmApiException(retCode, errorHeader, errorBody, activeConnection.getURL().toString(),
    729                             doAuthenticate ? retrieveBasicAuthorizationLogin(client) : null);
     729                            doAuthenticate ? retrieveBasicAuthorizationLogin(client) : null, response.getContentType());
    730730                default:
    731731                    throw new OsmApiException(retCode, errorHeader, errorBody);
  • trunk/src/org/openstreetmap/josm/io/OsmApiException.java

    r13493 r13499  
    1212
    1313    private int responseCode;
     14    private String contentType;
    1415    private String errorHeader;
    1516    private String errorBody;
     
    2526     * @param accessedUrl The complete URL accessed when this error occured
    2627     * @param login the login used to connect to OSM API (can be null)
    27      * @since 12992
    28      */
    29     public OsmApiException(int responseCode, String errorHeader, String errorBody, String accessedUrl, String login) {
     28     * @param contentType the response content-type
     29     * @since 13499
     30     */
     31    public OsmApiException(int responseCode, String errorHeader, String errorBody, String accessedUrl, String login, String contentType) {
    3032        this.responseCode = responseCode;
    3133        this.errorHeader = errorHeader;
     
    3335        this.accessedUrl = accessedUrl;
    3436        this.login = login;
     37        this.contentType = contentType;
     38    }
     39
     40    /**
     41     * Constructs an {@code OsmApiException} with the specified response code, error header and error body
     42     * @param responseCode The HTTP response code replied by the OSM server.
     43     * See {@link java.net.HttpURLConnection HttpURLConnection} for predefined HTTP response code values
     44     * @param errorHeader The error header, as transmitted in the {@code Error} field of the HTTP response header
     45     * @param errorBody The error body, as transmitted in the HTTP response body
     46     * @param accessedUrl The complete URL accessed when this error occured
     47     * @param login the login used to connect to OSM API (can be null)
     48     * @since 12992
     49     */
     50    public OsmApiException(int responseCode, String errorHeader, String errorBody, String accessedUrl, String login) {
     51        this(responseCode, errorHeader, errorBody, accessedUrl, login, null);
    3552    }
    3653
     
    233250        return login;
    234251    }
     252
     253    /**
     254     * Sets the response content-type.
     255     * @param contentType the response content-type.
     256     * @since 13499
     257     */
     258    public final void setContentType(String contentType) {
     259        this.contentType = contentType;
     260    }
     261
     262    /**
     263     * Replies the response content-type.
     264     * @return the response content-type
     265     * @since 13499
     266     */
     267    public final String getContentType() {
     268        return contentType;
     269    }
    235270}
  • trunk/src/org/openstreetmap/josm/io/OsmServerReader.java

    r13356 r13499  
    208208                    String errorHeader = response.getHeaderField("Error");
    209209                    String errorBody = fetchResponseText(response);
    210                     throw new OsmApiException(response.getResponseCode(), errorHeader, errorBody, url.toString());
     210                    throw new OsmApiException(response.getResponseCode(), errorHeader, errorBody, url.toString(), null,
     211                            response.getContentType());
    211212                }
    212213
Note: See TracChangeset for help on using the changeset viewer.