
package info.freelibrary.jiiify.verticles;

import static info.freelibrary.jiiify.Constants.FAILURE_RESPONSE;
import static info.freelibrary.jiiify.Constants.FILE_PATH_KEY;
import static info.freelibrary.jiiify.Constants.IIIF_PATH_KEY;
import static info.freelibrary.jiiify.Constants.SUCCESS_RESPONSE;

import java.io.File;
import java.io.IOException;

import javax.naming.ConfigurationException;

import info.freelibrary.jiiify.MessageCodes;
import info.freelibrary.jiiify.iiif.ImageRequest;
import info.freelibrary.jiiify.util.ImageUtils;

import io.vertx.core.Future;
import io.vertx.core.json.JsonObject;

public class ImageWorkerVerticle extends AbstractJiiifyVerticle {

    @Override
    public void start(final Future<Void> aFuture) throws ConfigurationException, IOException {
        getJsonConsumer().handler(message -> {
            final JsonObject json = message.body();

            try {
                final ImageRequest request = new ImageRequest(json.getString(IIIF_PATH_KEY));
                final File imageFile = new File(json.getString(FILE_PATH_KEY));
                final File cacheFile = request.getCacheFile(getConfiguration().getDataDir());

                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Creating derivative image for: {}", request.getID());
                }

                ImageUtils.transform(imageFile, request, cacheFile);
                message.reply(SUCCESS_RESPONSE);
            } catch (final Exception | OutOfMemoryError details) {
                LOGGER.error(details, MessageCodes.EXC_000, details.getMessage());
                message.reply(FAILURE_RESPONSE);
            }
        });

        aFuture.complete();
    }

}

@@ -1480,27 +1480,8 @@
 ion 
-%7C OutOfMemoryError 
 deta
@@ -1611,32 +1611,230 @@
 LURE_RESPONSE);%0A
+            %7D catch (final OutOfMemoryError details) %7B%0A                LOGGER.error(details, %22OutOfMemoryError: %7B%7D%22, json.getString(IIIF_PATH_KEY));%0A                message.reply(FAILURE_RESPONSE);%0A
             %7D%0A  

Add better error message on OutOfMemoryError