Changeset 2862 in josm for trunk


Ignore:
Timestamp:
2010-01-15T11:29:36+01:00 (14 years ago)
Author:
Gubaer
Message:

fixed #4322: No error message if trying to upload without OAuth token

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

Legend:

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

    r2801 r2862  
    1515import org.openstreetmap.josm.Main;
    1616import org.openstreetmap.josm.io.ChangesetClosedException;
     17import org.openstreetmap.josm.io.MissingOAuthAccessTokenException;
    1718import org.openstreetmap.josm.io.OsmApiException;
    1819import org.openstreetmap.josm.io.OsmApiInitializationException;
     
    269270
    270271    /**
     272     * Explains a {@see OsmApiException} which was thrown because accessing a protected
     273     * resource was forbidden.
     274     *
     275     * @param e the exception
     276     */
     277    public static void explainMissingOAuthAccessTokenException(MissingOAuthAccessTokenException e) {
     278        HelpAwareOptionPane.showOptionDialog(
     279                Main.parent,
     280                ExceptionUtil.explainMissingOAuthAccessTokenException(e),
     281                tr("Authenticationi failed"),
     282                JOptionPane.ERROR_MESSAGE,
     283                ht("/ErrorMessages#MissingOAuthAccessToken")
     284        );
     285    }
     286
     287    /**
    271288     * Explains a {@see UnknownHostException} which has caused an {@see OsmTransferException}.
    272289     * This is most likely happening when there is an error in the API URL or when
     
    340357        }
    341358
     359        if (e instanceof MissingOAuthAccessTokenException) {
     360            explainMissingOAuthAccessTokenException((MissingOAuthAccessTokenException)e);
     361            return;
     362        }
     363
    342364        if (e instanceof OsmApiException) {
    343365            OsmApiException oae = (OsmApiException) e;
     
    368390                return;
    369391            }
    370             explainGeneric(e);
    371         }
     392        }
     393        explainGeneric(e);
    372394    }
    373395
  • trunk/src/org/openstreetmap/josm/gui/io/UploadPrimitivesTask.java

    r2825 r2862  
    228228    @Override protected void realRun() throws SAXException, IOException {
    229229        try {
    230             uploadloop: while(true) {
     230            uploadloop:while(true) {
    231231                try {
    232232                    getProgressMonitor().subTask(tr("Uploading {0} objects ...", toUpload.getSize()));
     
    241241                    break;
    242242                } catch(OsmTransferCancelledException e) {
     243                    e.printStackTrace();
    243244                    uploadCancelled = true;
    244245                    return;
     
    343344                    handleFailedUpload(lastException);
    344345                }
    345 
    346346            }
    347347        };
  • trunk/src/org/openstreetmap/josm/io/OsmConnection.java

    r2801 r2862  
    118118        OAuthAccessTokenHolder holder = OAuthAccessTokenHolder.getInstance();
    119119        if (! holder.containsAccessToken())
    120             throw new OsmTransferException(tr("Failed to add an OAuth authentication header. There is currently no OAuth Access Token configured."));
    121 
     120            throw new MissingOAuthAccessTokenException();
    122121        consumer.setTokenWithSecret(holder.getAccessTokenKey(), holder.getAccessTokenSecret());
    123122        try {
  • trunk/src/org/openstreetmap/josm/tools/ExceptionUtil.java

    r2853 r2862  
    2121import org.openstreetmap.josm.gui.preferences.server.OAuthAccessTokenHolder;
    2222import org.openstreetmap.josm.io.ChangesetClosedException;
     23import org.openstreetmap.josm.io.MissingOAuthAccessTokenException;
    2324import org.openstreetmap.josm.io.OsmApi;
    2425import org.openstreetmap.josm.io.OsmApiException;
     
    4142                + "Check the server URL in your preferences and your internet connection.</html>", Main.pref.get(
    4243                        "osm-server.url", "http://api.openstreetmap.org/api"));
     44        return msg;
     45    }
     46
     47
     48    /**
     49     *  Creates the error message
     50     *
     51     * @param e the exception
     52     */
     53    public static String explainMissingOAuthAccessTokenException(MissingOAuthAccessTokenException e) {
     54        e.printStackTrace();
     55        String msg = tr(
     56                "<html>Failed to authenticate at the OSM server ''{0}''.<br>"
     57                + "You are using OAuth to authenticate but currently there is no<br>"
     58                + "OAuth Access Token configured.<br>"
     59                + "Please open the Preferences Dialog and generate or enter an Access Token."
     60                + "</html>",
     61                Main.pref.get("osm-server.url", "http://api.openstreetmap.org/api")
     62        );
    4363        return msg;
    4464    }
Note: See TracChangeset for help on using the changeset viewer.