Search in sources :

Example 31 with Error

use of io.spine.base.Error in project core-java by SpineEventEngine.

the class DuplicateCommandException method of.

/**
 * Creates an exception for a duplicate command.
 *
 * @param command the duplicate command
 * @return a newly constructed instance
 */
public static DuplicateCommandException of(Command command) {
    final CommandEnvelope envelope = CommandEnvelope.of(command);
    final Message commandMessage = envelope.getMessage();
    final String errorMessage = aggregateErrorMessage(envelope);
    final Error error = error(commandMessage, errorMessage);
    return new DuplicateCommandException(errorMessage, command, error);
}
Also used : Message(com.google.protobuf.Message) CommandEnvelope(io.spine.core.CommandEnvelope) Error(io.spine.base.Error) CommandValidationError(io.spine.core.CommandValidationError)

Example 32 with Error

use of io.spine.base.Error in project core-java by SpineEventEngine.

the class InvalidCommandException method onInapplicableTenantId.

public static InvalidCommandException onInapplicableTenantId(Command command) {
    final CommandEnvelope cmd = CommandEnvelope.of(command);
    final TypeName typeName = TypeName.of(cmd.getMessage());
    final String errMsg = format("The command (class: %s, type: %s, id: %s) was posted to single-tenant " + "CommandBus, but has tenant_id: %s attribute set in the command context.", cmd.getMessageClass(), typeName, cmd.getId(), cmd.getTenantId());
    final Error error = inapplicableTenantError(cmd.getMessage(), errMsg);
    return new InvalidCommandException(errMsg, command, error);
}
Also used : TypeName(io.spine.type.TypeName) CommandEnvelope(io.spine.core.CommandEnvelope) Error(io.spine.base.Error) CommandValidationError(io.spine.core.CommandValidationError)

Example 33 with Error

use of io.spine.base.Error in project core-java by SpineEventEngine.

the class InvalidCommandException method onMissingTenantId.

/**
 * Creates an exception for a command with missing {@code tenant_id} attribute in
 * the {@code CommandContext}, which is required in a multitenant application.
 */
public static InvalidCommandException onMissingTenantId(Command command) {
    final CommandEnvelope envelope = CommandEnvelope.of(command);
    final Message commandMessage = envelope.getMessage();
    final String errMsg = format("The command (class: `%s`, type: `%s`, id: `%s`) is posted to " + "multitenant Command Bus, but has no `tenant_id` attribute in the context.", CommandClass.of(commandMessage).value().getName(), TypeName.of(commandMessage), Identifier.toString(envelope.getId()));
    final Error error = unknownTenantError(commandMessage, errMsg);
    return new InvalidCommandException(errMsg, command, error);
}
Also used : Message(com.google.protobuf.Message) CommandEnvelope(io.spine.core.CommandEnvelope) Error(io.spine.base.Error) CommandValidationError(io.spine.core.CommandValidationError)

Example 34 with Error

use of io.spine.base.Error in project core-java by SpineEventEngine.

the class Rescheduler method onScheduledCommandExpired.

/**
 * Sets the status of the expired command to error.
 *
 * <p>We cannot post such a command because there is no handler or dispatcher registered yet.
 * Or, posting such a command may be undesirable from the business logic point of view.
 *
 * @param command the expired command
 * @see CommandExpiredException
 */
private void onScheduledCommandExpired(Command command) {
    final CommandEnvelope commandEnvelope = CommandEnvelope.of(command);
    final Message msg = commandEnvelope.getMessage();
    final CommandId id = commandEnvelope.getId();
    final Error error = CommandExpiredException.commandExpired(command);
    commandStore().setToError(commandEnvelope, error);
    log().errorExpiredCommand(msg, id);
}
Also used : Message(com.google.protobuf.Message) CommandEnvelope(io.spine.core.CommandEnvelope) Error(io.spine.base.Error) CommandId(io.spine.core.CommandId)

Example 35 with Error

use of io.spine.base.Error in project core-java by SpineEventEngine.

the class StreamObserversShould method return_Error_extracted_from_StatusRuntimeException_metadata.

/*
     * Error extraction tests
     **************************/
@Test
public void return_Error_extracted_from_StatusRuntimeException_metadata() {
    final Error expectedError = Error.getDefaultInstance();
    final Metadata metadata = MetadataConverter.toMetadata(expectedError);
    final StatusRuntimeException statusRuntimeException = INVALID_ARGUMENT.asRuntimeException(metadata);
    assertEquals(expectedError, StreamObservers.fromStreamError(statusRuntimeException).get());
}
Also used : Metadata(io.grpc.Metadata) StatusRuntimeException(io.grpc.StatusRuntimeException) Error(io.spine.base.Error) Test(org.junit.Test)

Aggregations

Error (io.spine.base.Error)35 Test (org.junit.Test)19 Ack (io.spine.core.Ack)11 Command (io.spine.core.Command)8 Message (com.google.protobuf.Message)6 Metadata (io.grpc.Metadata)6 CommandValidationError (io.spine.core.CommandValidationError)6 CommandEnvelope (io.spine.core.CommandEnvelope)5 CommandId (io.spine.core.CommandId)5 Event (io.spine.core.Event)5 Rejection (io.spine.core.Rejection)4 TenantId (io.spine.core.TenantId)4 BoundedContext (io.spine.server.BoundedContext)4 ThrowableMessage (io.spine.base.ThrowableMessage)3 Status (io.spine.core.Status)3 AggregateMessageDispatcher.dispatchCommand (io.spine.server.aggregate.AggregateMessageDispatcher.dispatchCommand)3 AggregateMessageDispatcher.dispatchRejection (io.spine.server.aggregate.AggregateMessageDispatcher.dispatchRejection)3 AggregateTestEnv.newTaskBoundedContext (io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTaskBoundedContext)3 AggregateTestEnv.newTenantId (io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTenantId)3 CommandRecord (io.spine.server.commandbus.CommandRecord)3