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


Ignore:
Timestamp:
2015-07-16T21:13:12+02:00 (9 years ago)
Author:
wiktorn
Message:

Properly report exceptions from tile download

Location:
trunk/src/org/openstreetmap/josm/data
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/cache/CacheEntryAttributes.java

    r8510 r8606  
    2828    private static final String EXPIRATION_TIME = "expirationTime";
    2929    private static final String HTTP_RESPONSE_CODE = "httpResponceCode";
     30    private static final String ERROR_MESSAGE = "errorMessage";
    3031    // this contains all of the above
    3132    private static final Set<String> RESERVED_KEYS = new HashSet<>(Arrays.asList(new String[]{
     
    3435        LAST_MODIFICATION,
    3536        EXPIRATION_TIME,
    36         HTTP_RESPONSE_CODE
     37        HTTP_RESPONSE_CODE,
     38        ERROR_MESSAGE
    3739    }));
     40
    3841
    3942    /**
     
    176179        return Collections.unmodifiableMap(attrs);
    177180    }
     181
     182    /**
     183     * @return error message returned while retrieving this object
     184     */
     185    public String getErrorMessage() {
     186        return attrs.get(ERROR_MESSAGE);
     187    }
     188
     189    /**
     190     * @param message error message related to this object
     191     */
     192    public void setErrorMessage(String message) {
     193        attrs.put(ERROR_MESSAGE, message);
     194    }
    178195}
  • trunk/src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java

    r8604 r8606  
    369369            log.log(Level.FINE, "JCS - Caching empty object as server returned 404 for: {0}", getUrl());
    370370            attributes.setResponseCode(404);
     371            attributes.setErrorMessage(e.toString());
    371372            boolean doCache = isResponseLoadable(null, 404, null) || cacheAsEmpty();
    372373            if (doCache) {
     
    377378        } catch (IOException e) {
    378379            log.log(Level.FINE, "JCS - IOExecption during communication with server for: {0}", getUrl());
    379 
     380            attributes.setErrorMessage(e.toString());
    380381            attributes.setResponseCode(499); // set dummy error code
    381382            boolean doCache = isResponseLoadable(null, 499, null) || cacheAsEmpty(); //generic 499 error code returned
     
    386387            return doCache;
    387388        } catch (Exception e) {
     389            attributes.setErrorMessage(e.toString());
    388390            log.log(Level.WARNING, "JCS - Exception during download {0}",  getUrl());
    389391            Main.warn(e);
  • trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java

    r8598 r8606  
    188188                    }
    189189                    int httpStatusCode = attributes.getResponseCode();
    190                     if (!isNoTileAtZoom() && httpStatusCode >= 400) {
    191                         tile.setError(tr("HTTP error {0} when loading tiles", httpStatusCode));
     190                    if (!isNoTileAtZoom() && httpStatusCode >= 400 && httpStatusCode != 499) {
     191                        if (attributes.getErrorMessage() == null) {
     192                            tile.setError(tr("HTTP error {0} when loading tiles", httpStatusCode));
     193                        } else {
     194                            tile.setError(tr("Error downloading tiles: {0}", attributes.getErrorMessage()));
     195                        }
    192196                        status = false;
    193197                    }
     
    209213        } catch (IOException e) {
    210214            LOG.log(Level.WARNING, "JCS TMS - error loading object for tile {0}: {1}", new Object[] {tile.getKey(), e.getMessage()});
    211             tile.setError(e.getMessage());
     215            tile.setError(e.toString());
    212216            tile.setLoaded(false);
    213217            if (listeners != null) { // listeners might be null, if some other thread notified already about success
     
    285289                    tile.finishLoading();
    286290                }
    287                 if (attributes.getResponseCode() >= 400) {
     291                if (attributes.getErrorMessage() == null) {
    288292                    tile.setError(tr("HTTP error {0} when loading tiles", attributes.getResponseCode()));
     293                } else {
     294                    tile.setError(tr("Error downloading tiles: {0}", attributes.getErrorMessage()));
    289295                }
    290296                return tile;
Note: See TracChangeset for help on using the changeset viewer.