package com.atlassian.stash.internal.web.util;

import com.atlassian.soy.springmvc.errors.DetailedError;
import com.atlassian.bitbucket.RequestCanceledException;
import com.atlassian.bitbucket.i18n.KeyedMessage;
import com.google.common.base.Function;
import com.google.common.collect.Lists;

public class StashWebErrorUtils {

    private StashWebErrorUtils() {
        throw new UnsupportedOperationException(getClass().getName() +
                " is a utility class and should not be instantiated");
    }

    public static DetailedError toDetailedError(RequestCanceledException e) {
        return new DetailedError(e.getLocalizedMessage(), Lists.transform(e.getCancelMessages(), new Function<KeyedMessage, String>() {

            @Override
            public String apply(KeyedMessage message) {
                return message.getLocalisedMessage();
            }
        }));
    }
}
