Search in sources :

Example 11 with Error

use of com.nexblocks.authguard.api.dto.entities.Error in project AuthGuard by AuthGuard.

the class ExceptionHandlers method idempotencyException.

public static void idempotencyException(final IdempotencyException e, final Context context) {
    final IdempotentRecordBO record = e.getIdempotentRecord();
    final Error error = new Error(ErrorCode.IDEMPOTENCY_ERROR.getCode(), String.format("Idempotent key %s was already used to create entity %s of type %s", record.getIdempotentKey(), record.getEntityId(), record.getEntityType()));
    context.status(409).json(error);
}
Also used : IdempotentRecordBO(com.nexblocks.authguard.service.model.IdempotentRecordBO) Error(com.nexblocks.authguard.api.dto.entities.Error) RequestValidationError(com.nexblocks.authguard.api.dto.entities.RequestValidationError)

Example 12 with Error

use of com.nexblocks.authguard.api.dto.entities.Error in project AuthGuard by AuthGuard.

the class ExceptionHandlers method serviceConflictException.

public static void serviceConflictException(final ServiceConflictException e, final Context context) {
    LOG.info("Service conflict exception was thrown");
    final Error error = new Error(e.getErrorCode(), e.getMessage());
    context.status(409).json(error);
}
Also used : Error(com.nexblocks.authguard.api.dto.entities.Error) RequestValidationError(com.nexblocks.authguard.api.dto.entities.RequestValidationError)

Example 13 with Error

use of com.nexblocks.authguard.api.dto.entities.Error in project AuthGuard by AuthGuard.

the class AccountsRoute method getById.

public void getById(final Context context) {
    final String accountId = context.pathParam("id");
    final Optional<AccountDTO> account = accountsService.getById(accountId).map(restMapper::toDTO);
    if (account.isPresent()) {
        context.status(200).json(account.get());
    } else {
        context.status(404).json(new Error(ErrorCode.ACCOUNT_DOES_NOT_EXIST.getCode(), "Account not found"));
    }
}
Also used : Error(com.nexblocks.authguard.api.dto.entities.Error) AccountDTO(com.nexblocks.authguard.api.dto.entities.AccountDTO)

Example 14 with Error

use of com.nexblocks.authguard.api.dto.entities.Error in project AuthGuard by AuthGuard.

the class AccountsRoute method getByExternalId.

public void getByExternalId(final Context context) {
    final String accountId = context.pathParam("id");
    final Optional<AccountDTO> account = accountsService.getByExternalId(accountId).map(restMapper::toDTO);
    if (account.isPresent()) {
        context.status(200).json(account.get());
    } else {
        context.status(404).json(new Error(ErrorCode.ACCOUNT_DOES_NOT_EXIST.getCode(), "Account not found"));
    }
}
Also used : Error(com.nexblocks.authguard.api.dto.entities.Error) AccountDTO(com.nexblocks.authguard.api.dto.entities.AccountDTO)

Example 15 with Error

use of com.nexblocks.authguard.api.dto.entities.Error in project AuthGuard by AuthGuard.

the class AccountsRoute method deactivate.

public void deactivate(final Context context) {
    final String accountId = context.pathParam("id");
    final Optional<AccountDTO> account = accountsService.deactivate(accountId).map(restMapper::toDTO);
    if (account.isPresent()) {
        context.status(200).json(account.get());
    } else {
        context.status(404).json(new Error("404", "No account with ID " + accountId + " exists"));
    }
}
Also used : Error(com.nexblocks.authguard.api.dto.entities.Error) AccountDTO(com.nexblocks.authguard.api.dto.entities.AccountDTO)

Aggregations

Error (com.nexblocks.authguard.api.dto.entities.Error)31 AccountDTO (com.nexblocks.authguard.api.dto.entities.AccountDTO)9 RequestValidationError (com.nexblocks.authguard.api.dto.entities.RequestValidationError)7 Inject (com.google.inject.Inject)4 AuthRequestDTO (com.nexblocks.authguard.api.dto.requests.AuthRequestDTO)4 RestMapper (com.nexblocks.authguard.rest.mappers.RestMapper)4 BodyHandler (com.nexblocks.authguard.rest.util.BodyHandler)4 IdempotencyHeader (com.nexblocks.authguard.rest.util.IdempotencyHeader)4 Context (io.javalin.http.Context)4 List (java.util.List)4 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 AuthGuardRoles (com.nexblocks.authguard.api.access.AuthGuardRoles)3 ApiKeyDTO (com.nexblocks.authguard.api.dto.entities.ApiKeyDTO)3 AppDTO (com.nexblocks.authguard.api.dto.entities.AppDTO)3 ActorDomainVerifier (com.nexblocks.authguard.rest.access.ActorDomainVerifier)3 ApplicationsService (com.nexblocks.authguard.service.ApplicationsService)3 CredentialsService (com.nexblocks.authguard.service.CredentialsService)3 IdempotencyException (com.nexblocks.authguard.service.exceptions.IdempotencyException)3 com.nexblocks.authguard.service.model (com.nexblocks.authguard.service.model)3