use of com.nexblocks.authguard.service.exceptions.ServiceConflictException in project AuthGuard by AuthGuard.
the class ExceptionHandlers method completionException.
// NOTE: this will go away when we move to async services
public static void completionException(final CompletionException e, final Context context) {
final Throwable cause = e.getCause();
if (cause == null) {
LOG.error("A CompletionException was thrown without a cause", e);
context.status(500).json(new Error("UNKNOWN", "An unknown error occurred"));
} else if (cause instanceof ServiceAuthorizationException) {
serviceAuthorizationException((ServiceAuthorizationException) cause, context);
} else if (cause instanceof ServiceConflictException) {
serviceConflictException((ServiceConflictException) cause, context);
} else if (cause instanceof ServiceException) {
serviceException((ServiceException) cause, context);
} else if (cause instanceof RuntimeJsonException) {
jsonMappingException((RuntimeJsonException) cause, context);
} else if (cause instanceof RequestValidationException) {
requestValidationException((RequestValidationException) cause, context);
} else if (cause instanceof IdempotencyException) {
idempotencyException((IdempotencyException) cause, context);
} else if (cause instanceof TimeoutException) {
timeoutException((TimeoutException) cause, context);
} else {
LOG.error("An unexpected exception was thrown", cause);
context.status(500).json(new Error("UNKNOWN", "An unknown error occurred"));
}
}
use of com.nexblocks.authguard.service.exceptions.ServiceConflictException in project AuthGuard by AuthGuard.
the class CredentialsServiceImpl method addIdentifiers.
@Override
public Optional<CredentialsBO> addIdentifiers(final String id, final List<UserIdentifierBO> identifiers) {
final CredentialsBO existing = getByIdUnsafe(id).orElseThrow(() -> new ServiceNotFoundException(ErrorCode.IDENTIFIER_DOES_NOT_EXIST, "No credentials with ID " + id));
final Set<String> existingIdentifiers = existing.getIdentifiers().stream().map(UserIdentifierBO::getIdentifier).collect(Collectors.toSet());
final List<UserIdentifierBO> combined = new ArrayList<>(existing.getIdentifiers());
for (final UserIdentifierBO identifier : identifiers) {
if (existingIdentifiers.contains(identifier.getIdentifier())) {
throw new ServiceConflictException(ErrorCode.IDENTIFIER_ALREADY_EXISTS, "Duplicate identifier for " + id);
}
combined.add(UserIdentifierBO.builder().from(identifier).active(true).domain(existing.getDomain()).build());
}
final CredentialsBO updated = CredentialsBO.builder().from(existing).identifiers(combined).build();
return doUpdate(existing, updated, false);
}
Aggregations