All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.polyglotted.eswrapper.services.IndexerException Maven / Gradle / Ivy

There is a newer version: 2.4.3
Show newest version
package io.polyglotted.eswrapper.services;

import com.google.common.collect.ImmutableMap;

import java.util.Map;
import java.util.Map.Entry;

@SuppressWarnings("serial")
public class IndexerException extends RuntimeException {
    public final ImmutableMap errorsMap;

    protected IndexerException(ImmutableMap errorsMap) {
        super((String) errorsMap.get("ERROR_MESSAGE"));
        this.errorsMap = errorsMap;
    }

    public static  void checkErrors(Map errorsMap) {
        if (!errorsMap.isEmpty()) {
            throw new IndexerException(ImmutableMap.of("ERROR_MESSAGE",
               buildFailureMessage("indexing failed:", errorsMap), "ERRORS", errorsMap));
        }
    }

    static  String buildFailureMessage(String message, Map  errorsMap) {
        StringBuilder sb = new StringBuilder();
        sb.append(message);
        for (Entry entry : errorsMap.entrySet())
            sb.append("\n[").append(entry.getKey()).append("]: ").append(entry.getValue());
        return sb.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy