Search in sources :

Example 1 with ServiceConflictException

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"));
    }
}
Also used : ServiceConflictException(com.nexblocks.authguard.service.exceptions.ServiceConflictException) ServiceException(com.nexblocks.authguard.service.exceptions.ServiceException) IdempotencyException(com.nexblocks.authguard.service.exceptions.IdempotencyException) ServiceAuthorizationException(com.nexblocks.authguard.service.exceptions.ServiceAuthorizationException) Error(com.nexblocks.authguard.api.dto.entities.Error) RequestValidationError(com.nexblocks.authguard.api.dto.entities.RequestValidationError) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with ServiceConflictException

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);
}
Also used : ServiceConflictException(com.nexblocks.authguard.service.exceptions.ServiceConflictException) ServiceNotFoundException(com.nexblocks.authguard.service.exceptions.ServiceNotFoundException) ArrayList(java.util.ArrayList)

Aggregations

ServiceConflictException (com.nexblocks.authguard.service.exceptions.ServiceConflictException)2 Error (com.nexblocks.authguard.api.dto.entities.Error)1 RequestValidationError (com.nexblocks.authguard.api.dto.entities.RequestValidationError)1 IdempotencyException (com.nexblocks.authguard.service.exceptions.IdempotencyException)1 ServiceAuthorizationException (com.nexblocks.authguard.service.exceptions.ServiceAuthorizationException)1 ServiceException (com.nexblocks.authguard.service.exceptions.ServiceException)1 ServiceNotFoundException (com.nexblocks.authguard.service.exceptions.ServiceNotFoundException)1 ArrayList (java.util.ArrayList)1 TimeoutException (java.util.concurrent.TimeoutException)1