public final class DuplicateFieldError extends SphereError
Example for duplicate customer email
public class DuplicateFieldErrorIntegrationTest extends IntegrationTest {
@Test
public void customerAlreadyRegistered() {
withCustomer(client(), customer -> {
final String email = customer.getEmail();
final CustomerDraftDsl draft = CustomerDraftBuilder.of(email, "secret")
.build();
final CustomerCreateCommand cmd = CustomerCreateCommand.of(draft);
final Throwable throwable = catchThrowable(() -> client().executeBlocking(cmd));
assertThat(throwable).isInstanceOf(ErrorResponseException.class);
final ErrorResponseException e = (ErrorResponseException) throwable;
assertThat(e.getErrors().get(0).getCode()).isEqualTo(DuplicateFieldError.CODE);
final DuplicateFieldError error = e.getErrors().get(0).as(DuplicateFieldError.class);
assertThat(error.getDuplicateValue()).isEqualToIgnoringCase(email);
assertThat(error.getField()).isEqualTo("email");
});
}
}
See the test code.
ErrorResponseException
Modifier and Type | Method and Description |
---|---|
String |
getDuplicateValue() |
String |
getField() |
static DuplicateFieldError |
of(String message,
String duplicateValue,
String field) |
as, getCode, getMessage, of
public static final String CODE