package com.atlassian.bitbucket.mesh.repository;

import com.atlassian.bitbucket.mesh.AbstractStatusException;
import com.atlassian.bitbucket.mesh.rpc.v1.RpcDataStoreUnavailable;
import com.atlassian.bitbucket.mesh.rpc.v1.RpcError;
import com.atlassian.bitbucket.mesh.rpc.v1.RpcErrorUtils;
import io.grpc.Metadata;
import io.grpc.Status;

import javax.annotation.Nullable;

public class DataStoreUnavailableException extends AbstractStatusException {

    public DataStoreUnavailableException(@Nullable String message) {
        super(message, Status.FAILED_PRECONDITION);
    }

    @Override
    protected Metadata getTrailers() {
        return RpcErrorUtils.toMetadata(RpcError.newBuilder()
                .setDataStoreUnavailable(RpcDataStoreUnavailable.getDefaultInstance())
                .build());
    }
}
