Search in sources :

Example 1 with UnauthorizedException

use of org.thingsboard.server.extensions.api.exception.UnauthorizedException in project thingsboard by thingsboard.

the class ValidationCallback method onSuccess.

@Override
public void onSuccess(PluginContext ctx, ValidationResult result) {
    ValidationResultCode resultCode = result.getResultCode();
    if (resultCode == ValidationResultCode.OK) {
        action.accept(ctx);
    } else {
        Exception e;
        switch(resultCode) {
            case ENTITY_NOT_FOUND:
                e = new EntityNotFoundException(result.getMessage());
                break;
            case UNAUTHORIZED:
                e = new UnauthorizedException(result.getMessage());
                break;
            case ACCESS_DENIED:
                e = new AccessDeniedException(result.getMessage());
                break;
            case INTERNAL_ERROR:
                e = new InternalErrorException(result.getMessage());
                break;
            default:
                e = new UnauthorizedException("Permission denied.");
                break;
        }
        onFailure(ctx, e);
    }
}
Also used : AccessDeniedException(org.thingsboard.server.extensions.api.exception.AccessDeniedException) UnauthorizedException(org.thingsboard.server.extensions.api.exception.UnauthorizedException) EntityNotFoundException(org.thingsboard.server.extensions.api.exception.EntityNotFoundException) InternalErrorException(org.thingsboard.server.extensions.api.exception.InternalErrorException) AccessDeniedException(org.thingsboard.server.extensions.api.exception.AccessDeniedException) UnauthorizedException(org.thingsboard.server.extensions.api.exception.UnauthorizedException) EntityNotFoundException(org.thingsboard.server.extensions.api.exception.EntityNotFoundException) InternalErrorException(org.thingsboard.server.extensions.api.exception.InternalErrorException)

Aggregations

AccessDeniedException (org.thingsboard.server.extensions.api.exception.AccessDeniedException)1 EntityNotFoundException (org.thingsboard.server.extensions.api.exception.EntityNotFoundException)1 InternalErrorException (org.thingsboard.server.extensions.api.exception.InternalErrorException)1 UnauthorizedException (org.thingsboard.server.extensions.api.exception.UnauthorizedException)1