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

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

import javax.annotation.Nonnull;

/**
 * Constructing the DataSource does not actually retrieve any connections. As a result, there's no real validation
 * at that time on whether the database configuration is valid. The first bean which actually attempts to use the
 * database is the DefaultDatabaseSupplier, since it uses a connection to validate that the database is supported.
 * If it cannot get a database connection, it will throw a CannotGetJdbcConnectionException.
 *
 * @since 2.8.2
 */
public class ConnectionFailureHandler extends AbstractHelpPathProvider implements ExceptionFailureHandler {

    @Override
    public EventDetails handle(@Nonnull Throwable t) {
        String message = "The database, as currently configured, is not accessible. <br>" +
                t.getCause().getMessage();
        return new EventDetails("database-unavailable", message, t);
    }
}
