package com.atlassian.stash.internal.johnson.handler.exception;

import com.atlassian.bitbucket.Product;
import com.atlassian.stash.internal.johnson.AbstractHelpPathProvider;
import com.atlassian.stash.internal.johnson.handler.EventDetails;

import javax.annotation.Nonnull;

/**
 * @since 2.8.2
 */
public class UnsupportedJdbcUrlHandler extends AbstractHelpPathProvider implements ExceptionFailureHandler {

    @Override
    public EventDetails handle(@Nonnull Throwable t) {
        HelpDetails help = getHelp("bitbucket.help.db.unsupported.url", "our documentation",
                "https://confluence.atlassian.com/x/kIL_Eg");
        StringBuilder message = new StringBuilder(Product.NAME)
                .append(" is configured to use Microsoft SQL Server with a custom jTDS JDBC URL. jTDS support")
                .append(" was removed in the 2.1 release, so the configured URL is no longer valid. ")
                .append(Product.NAME)
                .append(" now uses Microsoft's JDBC driver. The configured URL must be manually updated to a")
                .append(" value compatible with the new driver.<br/><br/>")
                .append("See <a href=\"")
                .append(help.getUrl())
                .append("\">")
                .append(help.getTitle())
                .append("</a> for more details.");

        return new EventDetails("unsupported-jdbc-url", message.toString(), t);
    }
}
