Changeset 7205 in josm for trunk/src


Ignore:
Timestamp:
2014-06-01T15:00:00+02:00 (6 years ago)
Author:
Don-vip
Message:

fix #10052 - Wrong server URL in HTTP 400 error message

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/OsmApiException.java

    r6087 r7205  
    3636     */
    3737    public OsmApiException(int responseCode, String errorHeader, String errorBody) {
    38         this.responseCode = responseCode;
    39         this.errorHeader = errorHeader;
    40         this.errorBody = errorBody;
     38        this(responseCode, errorHeader, errorBody, null);
    4139    }
    4240
  • trunk/src/org/openstreetmap/josm/tools/ExceptionUtil.java

    r7187 r7205  
    4747     *
    4848     * @param e the exception
     49     * @return The HTML formatted error message to display
    4950     */
    5051    public static String explainOsmApiInitializationException(OsmApiInitializationException e) {
     
    5758
    5859
    59     /**
    60      *  Creates the error message
    61      *
    62      * @param e the exception
    63      */
    6460    public static String explainMissingOAuthAccessTokenException(MissingOAuthAccessTokenException e) {
    6561        Main.error(e);
     
    125121     *
    126122     * @param e the exception
     123     * @return The HTML formatted error message to display
    127124     */
    128125    public static String explainPreconditionFailed(OsmApiException e) {
     
    312309     *
    313310     * @param e the exception
    314      * @return the message
     311     * @return The HTML formatted error message to display
    315312     */
    316313    public static String explainClientTimeout(OsmApiException e) {
     
    327324     *
    328325     * @param e the exception
    329      * @return the message
     326     * @return The HTML formatted error message to display
    330327     */
    331328    public static String explainGenericOsmApiException(OsmApiException e) {
     
    354351     *
    355352     * @param e the exception
     353     * @return The HTML formatted error message to display
    356354     */
    357355    public static String explainConflict(OsmApiException e) {
     
    407405     *
    408406     * @param e the exception
     407     * @return The HTML formatted error message to display
    409408     */
    410409    public static String explainChangesetClosedException(ChangesetClosedException e) {
     
    423422     *
    424423     * @param e the exception
     424     * @return The HTML formatted error message to display
    425425     */
    426426    public static String explainGeneric(Exception e) {
     
    439439     *
    440440     * @param e the exception
    441      */
    442 
     441     * @return The HTML formatted error message to display
     442     */
    443443    public static String explainSecurityException(OsmTransferException e) {
    444444        String apiUrl = e.getUrl();
     
    461461     *
    462462     * @param e the exception
     463     * @return The HTML formatted error message to display
    463464     */
    464465    public static String explainNestedSocketException(OsmTransferException e) {
     
    474475     *
    475476     * @param e the exception
     477     * @return The HTML formatted error message to display
    476478     */
    477479    public static String explainNestedIOException(OsmTransferException e) {
     
    489491     *
    490492     * @param e the exception
     493     * @return The HTML formatted error message to display
    491494     */
    492495    public static String explainNestedIllegalDataException(OsmTransferException e) {
     
    503506     *
    504507     * @param e the exception
     508     * @return The HTML formatted error message to display
    505509     */
    506510    public static String explainInternalServerError(OsmTransferException e) {
     
    511515
    512516    /**
    513      * Explains a {@link OsmApiException} which was thrown because of a bad
    514      * request
    515      *
    516      * @param e the exception
     517     * Explains a {@link OsmApiException} which was thrown because of a bad request.
     518     *
     519     * @param e the exception
     520     * @return The HTML formatted error message to display
    517521     */
    518522    public static String explainBadRequest(OsmApiException e) {
    519         String apiUrl = OsmApi.getOsmApi().getBaseUrl();
    520         String message = tr("The OSM server ''{0}'' reported a bad request.<br>", apiUrl);
    521         if (e.getErrorHeader() != null &&
    522                 (e.getErrorHeader().startsWith("The maximum bbox") ||
    523                         e.getErrorHeader().startsWith("You requested too many nodes"))) {
     523        String url = null;
     524        if (e.getAccessedUrl() != null) {
     525            try {
     526                url = new URL(e.getAccessedUrl()).getHost();
     527            } catch (MalformedURLException e1) {
     528                Main.warn(e1);
     529            }
     530        }
     531        if (url == null && e.getUrl() != null) {
     532            url = e.getUrl();
     533        } else if (url == null) {
     534            url = OsmApi.getOsmApi().getBaseUrl();
     535        }
     536        String message = tr("The OSM server ''{0}'' reported a bad request.<br>", url);
     537        String errorHeader = e.getErrorHeader();
     538        if (errorHeader != null && (errorHeader.startsWith("The maximum bbox") ||
     539                        errorHeader.startsWith("You requested too many nodes"))) {
    524540            message += "<br>"
    525541                + tr("The area you tried to download is too big or your request was too large."
    526542                        + "<br>Either request a smaller area or use an export file provided by the OSM community.");
    527         } else if (e.getErrorHeader() != null) {
    528             message += tr("<br>Error message(untranslated): {0}", e.getErrorHeader());
     543        } else if (errorHeader != null) {
     544            message += tr("<br>Error message(untranslated): {0}", errorHeader);
    529545        }
    530546        Main.error(e);
     
    537553     *
    538554     * @param e the exception
     555     * @return The HTML formatted error message to display
    539556     */
    540557    public static String explainBandwidthLimitExceeded(OsmApiException e) {
     
    548565     *
    549566     * @param e the exception
     567     * @return The HTML formatted error message to display
    550568     */
    551569    public static String explainNotFound(OsmApiException e) {
     
    566584     *
    567585     * @param e the exception
    568      */
    569 
     586     * @return The HTML formatted error message to display
     587     */
    570588    public static String explainNestedUnknownHostException(OsmTransferException e) {
    571589        String apiUrl = e.getUrl();
     
    609627     *
    610628     * @param e the {@link OsmTransferException}
     629     * @return The HTML formatted error message to display
    611630     */
    612631    public static String explainOsmTransferException(OsmTransferException e) {
     
    647666     *
    648667     * @param e the exception
     668     * @return The HTML formatted error message to display
    649669     */
    650670    public static String explainGoneForUnknownPrimitive(OsmApiException e) {
     
    662682     *
    663683     * @param e the {@link Exception}
     684     * @return The HTML formatted error message to display
    664685     */
    665686    public static String explainException(Exception e) {
Note: See TracChangeset for help on using the changeset viewer.