Nicer invalid update-url handling (for invalid world-names or non-existing worlds).

This commit is contained in:
FrozenCow 2011-02-26 20:27:54 +01:00
parent 5778611227
commit 1e04d10b35
3 changed files with 15 additions and 4 deletions

View File

@ -10,6 +10,10 @@ public class HttpErrorHandler {
response.getBody();
}
public static void handleForbidden(HttpResponse response) throws IOException {
handle(response, 403, "Forbidden");
}
public static void handleNotFound(HttpResponse response) throws IOException {
handle(response, 404, "Not found");
}

View File

@ -12,6 +12,7 @@ import org.bukkit.entity.Player;
import org.dynmap.Client;
import org.dynmap.MapManager;
import org.dynmap.PlayerList;
import org.dynmap.web.HttpErrorHandler;
import org.dynmap.web.HttpHandler;
import org.dynmap.web.HttpRequest;
import org.dynmap.web.HttpResponse;
@ -34,15 +35,19 @@ public class ClientUpdateHandler implements HttpHandler {
Matcher match = updatePathPattern.matcher(path);
if (!match.matches())
if (!match.matches()) {
HttpErrorHandler.handleForbidden(response);
return;
}
String worldName = match.group(1);
String timeKey = match.group(2);
World world = server.getWorld(worldName);
if (world == null)
if (world == null) {
HttpErrorHandler.handleNotFound(response);
return;
}
long current = System.currentTimeMillis();
long since = 0;

View File

@ -44,6 +44,8 @@ function DynMap(options) {
$.getJSON(me.options.updateUrl + 'configuration', function(configuration) {
me.configure(configuration);
me.initialize();
}, function(status, statusMessage) {
alert('Could not retrieve configuration: ' + statusMessage);
});
}
DynMap.prototype = {
@ -333,9 +335,9 @@ DynMap.prototype = {
//divs.filter(function(i){return parseInt(divs[i].attr('rel')) > timestamp+me.options.messagettl;}).remove();
});
setTimeout(function() { me.update(); }, me.options.updaterate);
}, function(request, statusText, ex) {
}, function(status, statusText, ex) {
me.alertbox
.text('Could not update map')
.text('Could not update map: ' + statusText)
.show();
setTimeout(function() { me.update(); }, me.options.updaterate);
}