* NEW: Improved rendering error messages. Fixes #22.

This commit is contained in:
Adrien Prokopowicz 2016-04-02 21:45:03 +02:00
parent a2cdb02834
commit b5d41b25d0
2 changed files with 21 additions and 2 deletions

View File

@ -75,7 +75,10 @@ public class NewCommand extends IoMCommand
public void errored(Throwable exception)
{
player.sendMessage("§cMap rendering failed : " + exception.getMessage());
PluginLogger.warning("Rendering from '{0}' failed", exception, player.getName());
PluginLogger.warning("Rendering from {0} failed : {1} : {2}",
player.getName(),
exception.getClass().getCanonicalName(),
exception.getMessage());
}
});
}

View File

@ -29,7 +29,10 @@ import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
@ -58,7 +61,20 @@ public class ImageRendererExecutor extends Worker
@Override
public ImageMap run() throws Throwable
{
final BufferedImage image = ImageIO.read(url);
final URLConnection connection = url.openConnection();
connection.connect();
if(connection instanceof HttpURLConnection)
{
final HttpURLConnection httpConnection = (HttpURLConnection) connection;
final int httpCode = httpConnection.getResponseCode();
if((httpCode / 100) != 2)
{
throw new IOException("HTTP error : " + httpCode + " " + httpConnection.getResponseMessage());
}
}
final InputStream stream = connection.getInputStream();
final BufferedImage image = ImageIO.read(stream);
if (image == null) throw new IOException("The given URL is not a valid image");
if (scaling) return RenderSingle(image, playerUUID);