package com.atlassian.bitbucket.mesh.transaction;

import com.atlassian.bitbucket.mesh.rpc.v1.RpcError;
import com.atlassian.bitbucket.mesh.rpc.v1.RpcErrorUtils;
import com.atlassian.bitbucket.mesh.rpc.v1.RpcTransactionLogError;
import io.grpc.Metadata;
import io.grpc.Status;
import io.grpc.StatusRuntimeException;

public class TransactionLogException extends StatusRuntimeException {

    private static final Metadata TRAILER = RpcErrorUtils.toMetadata(RpcError.newBuilder()
            .setTransactionLogError(RpcTransactionLogError.getDefaultInstance())
            .build());

    public TransactionLogException(String message) {
        this(message, null);
    }

    public TransactionLogException(String message, Throwable cause) {
        super(Status.INTERNAL.withDescription(message).withCause(cause), TRAILER);
    }
}
