Skip to content

Commit

Permalink
Added additional GwtErrorCodes
Browse files Browse the repository at this point in the history
Signed-off-by: Alberto Codutti <alberto.codutti@eurotech.com>
  • Loading branch information
Coduz committed Jul 14, 2021
1 parent da778ee commit 8ad47e6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
package org.eclipse.kapua.app.console.module.api.client;

public enum GwtKapuaErrorCode {
BUNDLE_START_ERROR,
BUNDLE_STOP_ERROR,
PACKAGE_URI_SYNTAX_ERROR,
CANNOT_REMOVE_LAST_ADMIN,
CURRENT_ADMIN_PASSWORD_DOES_NOT_MATCH,
DUPLICATE_NAME,
Expand All @@ -33,11 +30,7 @@ public enum GwtKapuaErrorCode {
INVALID_XSRF_TOKEN,
LOCKED_USER,
OVER_RULE_LIMIT,
BUNDLE_GET_ERROR,
INVENTORY_GET_ERROR,
REQUEST_BAD_METHOD,
UNAUTHENTICATED,
SEND_ERROR,
WARNING,
XSRF_INVALID_TOKEN,
PARENT_LIMIT_EXCEEDED_IN_CONFIG,
Expand All @@ -53,11 +46,22 @@ public enum GwtKapuaErrorCode {
END_BEFORE_START_TIME_ERROR,
SAME_START_AND_DATE,
SCHEDULE_DUPLICATE_NAME,
DOWNLOAD_PACKAGE_EXCEPTION,
TRIGGER_NEVER_FIRE,
JOB_STARTING_ERROR,
ADMIN_ROLE_DELETED_ERROR,
PERMISSION_DELETE_NOT_ALLOWED,
JOB_STOPPING_ERROR,
REQUIRE_MFA_CODE,

// Device Management Codes
BUNDLE_GET_ERROR,
BUNDLE_START_ERROR,
BUNDLE_STOP_ERROR,
DEVICE_MANAGEMENT_TIMEOUT,
DOWNLOAD_PACKAGE_EXCEPTION,
INVENTORY_GET_ERROR,
PACKAGE_URI_SYNTAX_ERROR,
REQUEST_BAD_METHOD,
RESPONSE_NOT_FOUND,
SEND_ERROR
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.eclipse.kapua.service.authentication.KapuaAuthenticationErrorCodes;
import org.eclipse.kapua.service.authentication.shiro.KapuaAuthenticationException;
import org.eclipse.kapua.service.authorization.shiro.exception.SubjectUnauthorizedException;
import org.eclipse.kapua.service.device.management.exception.DeviceManagementErrorCodes;
import org.eclipse.kapua.service.device.management.exception.DeviceManagementException;
import org.eclipse.kapua.service.elasticsearch.client.exception.ClientException;
import org.slf4j.Logger;
Expand Down Expand Up @@ -195,20 +196,37 @@ public static GwtKapuaException buildExceptionFromError(Throwable throwable) {
} else {
return new GwtKapuaException(GwtKapuaErrorCode.ILLEGAL_ARGUMENT, throwable, ((KapuaIllegalArgumentException) throwable).getArgumentName(), ((KapuaIllegalArgumentException) throwable).getArgumentValue());
}
}
//
// Device Management
else if (throwable instanceof KapuaException && ((KapuaException) throwable).getCode().name().equals(KapuaErrorCodes.BUNDLE_START_ERROR.name())) {
return new GwtKapuaException(GwtKapuaErrorCode.BUNDLE_START_ERROR, throwable, throwable.getLocalizedMessage());
} else if (throwable instanceof KapuaException && ((KapuaException) throwable).getCode().name().equals(KapuaErrorCodes.BUNDLE_START_ERROR.name())) {
return new GwtKapuaException(GwtKapuaErrorCode.BUNDLE_START_ERROR, throwable, throwable.getLocalizedMessage());
} else if (throwable instanceof KapuaException && ((KapuaException) throwable).getCode().name().equals(KapuaErrorCodes.BUNDLE_STOP_ERROR.name())) {
return new GwtKapuaException(GwtKapuaErrorCode.BUNDLE_STOP_ERROR, throwable, throwable.getLocalizedMessage());
} else if (throwable instanceof KapuaException && ((KapuaException) throwable).getCode().equals(KapuaErrorCodes.PACKAGE_URI_SYNTAX_ERROR)) {
return new GwtKapuaException(GwtKapuaErrorCode.PACKAGE_URI_SYNTAX_ERROR, throwable, throwable.getLocalizedMessage());
} else if (throwable instanceof KapuaMaxNumberOfItemsReachedException) {
return new GwtKapuaException(GwtKapuaErrorCode.MAX_NUMBER_OF_ITEMS_REACHED, throwable, ((KapuaMaxNumberOfItemsReachedException) throwable).getArgValue());
} else if (throwable instanceof KapuaException && ((KapuaException) throwable).getCode().equals(DeviceManagementErrorCodes.RESPONSE_NOT_FOUND)) {
return new GwtKapuaException(GwtKapuaErrorCode.RESPONSE_NOT_FOUND, throwable, throwable.getLocalizedMessage());
} else if (throwable instanceof KapuaException && ((KapuaException) throwable).getCode().equals(DeviceManagementErrorCodes.TIMEOUT)) {
return new GwtKapuaException(GwtKapuaErrorCode.DEVICE_MANAGEMENT_TIMEOUT, throwable, throwable.getLocalizedMessage());
} else if (throwable instanceof DeviceManagementException) {
return new GwtKapuaException(GwtKapuaErrorCode.valueOf(((DeviceManagementException) throwable).getCode().name()), throwable, throwable.getLocalizedMessage());
} else if (throwable instanceof KapuaException && ((KapuaException) throwable).getCode().name().equals(KapuaErrorCodes.PERMISSION_DELETE_NOT_ALLOWED.name())) {
}
//
// Service Limits
else if (throwable instanceof KapuaMaxNumberOfItemsReachedException) {
return new GwtKapuaException(GwtKapuaErrorCode.MAX_NUMBER_OF_ITEMS_REACHED, throwable, ((KapuaMaxNumberOfItemsReachedException) throwable).getArgValue());
}
//
// Permissions
else if (throwable instanceof KapuaException && ((KapuaException) throwable).getCode().name().equals(KapuaErrorCodes.PERMISSION_DELETE_NOT_ALLOWED.name())) {
return new GwtKapuaException(GwtKapuaErrorCode.PERMISSION_DELETE_NOT_ALLOWED, throwable, throwable.getLocalizedMessage());
} else {
// all others => log and return internal error code
}
//
// Default exception
else {
return GwtKapuaException.internalError(throwable, throwable.getLocalizedMessage());
}
}
Expand Down

0 comments on commit 8ad47e6

Please sign in to comment.