Changeset 1559 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2009-04-27T23:21:28+02:00 (16 years ago)
Author:
framm
Message:
  • improved error message handling for messages that come from the server.
Location:
trunk/src/org/openstreetmap/josm/io
Files:
2 edited

Legend:

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

    r1546 r1559  
    66import java.io.BufferedReader;
    77import java.io.BufferedWriter;
     8import java.io.IOException;
     9import java.io.InputStream;
    810import java.io.InputStreamReader;
    911import java.io.OutputStream;
     
    1921import java.util.ArrayList;
    2022import java.util.Collection;
    21 import java.util.HashMap;
    2223import java.util.Properties;
    2324import java.util.StringTokenizer;
     
    7879     */
    7980    private boolean initialized = false;
    80 
    81     /**
    82      * list of server error messages (as transported in the Error: header) and their translations.
    83      */
    84     public static final HashMap<String,String> serverErrorTranslations;
    85 
    86     static {
    87         serverErrorTranslations = new HashMap<String,String>();
    88         serverErrorTranslations.put("Database offline for maintenance",
    89             tr("Database offline for maintenance"));
    90         serverErrorTranslations.put("You must make your edits public to upload new data",
    91             tr("You must make your edits public to upload new data"));
    92         // FIXME there is one additional server error message that goes
    93         // "You requested too many nodes (limit is #{APP_CONFIG['max_number_of_nodes']}). Either request a smaller area, or use planet.osm"
    94         // but we would have to switch this mechanism to using regular expressions if we wanted to translate that...
    95     }
    9681   
    9782    private StringWriter swriter = new StringWriter();
     
    400385                    out.close();
    401386                }
     387               
    402388                activeConnection.connect();
    403389                System.out.println(activeConnection.getResponseMessage());
    404 
    405390                int retCode = activeConnection.getResponseCode();
    406391               
     
    414399                // populate return fields.
    415400                responseBody.setLength(0);
    416                 BufferedReader in = new BufferedReader(new InputStreamReader(activeConnection.getInputStream()));
     401               
     402                // If the API returned an error code like 403 forbidden, getInputStream
     403                // will fail with an IOException.
     404                InputStream i = null;
     405                try {
     406                    i = activeConnection.getInputStream();
     407                } catch (IOException ioe) {
     408                    i = activeConnection.getErrorStream();
     409                }
     410                BufferedReader in = new BufferedReader(new InputStreamReader(i));
     411               
    417412                String s;
    418413                while((s = in.readLine()) != null) {
     
    422417
    423418                statusMessage.setLength(0);
    424                 statusMessage.append (activeConnection.getResponseMessage());
    425419                // Look for a detailed error message from the server
    426420                if (activeConnection.getHeaderField("Error") != null) {
    427                     statusMessage.append(": ");
    428421                    String er = activeConnection.getHeaderField("Error");
    429                     if (serverErrorTranslations.containsKey(er)) er = serverErrorTranslations.get(er);
    430                     statusMessage.append(er);
     422                    System.err.println("Error header: " + er);
     423                    statusMessage.append(tr(er));
     424                } else if (retCode != 200 && responseBody.length()>0) {
     425                    System.err.println("Error body: " + responseBody);
     426                    statusMessage.append(tr(responseBody.toString()));
     427                } else {
     428                    statusMessage.append(activeConnection.getResponseMessage());
    431429                }
    432430                activeConnection.disconnect();
  • trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java

    r1546 r1559  
    66import java.util.Collection;
    77import java.util.LinkedList;
     8
     9import javax.swing.JOptionPane;
    810
    911import org.openstreetmap.josm.Main;
     
    125127
    126128    private void dealWithTransferException (OsmTransferException e) {
    127         Main.pleaseWaitDlg.currentAction.setText(tr("Transfer aborted due to error (will wait for 5 seconds):") + e.getMessage());
    128         try {
    129             Thread.sleep(5000);
    130         }
    131         catch (InterruptedException ex) {}
     129        JOptionPane.showMessageDialog(Main.parent,
     130            /* tr("Error during upload: ") + */ e.getMessage());
    132131    }
    133132}
Note: See TracChangeset for help on using the changeset viewer.