use of org.wso2.carbon.identity.branding.preference.management.core.exception.BrandingPreferenceMgtServerException in project identity-api-server by wso2.
the class BrandingPreferenceManagementService method handleBrandingPreferenceMgtException.
/**
* Handle branding preference management exceptions and return an API error.
*
* @param exception Branding preference management exception
* @param errorEnum Branding preference management error enum.
* @param data Relevant data.
* @return Processed API Error.
*/
private APIError handleBrandingPreferenceMgtException(BrandingPreferenceMgtException exception, BrandingPreferenceManagementConstants.ErrorMessage errorEnum, String data) {
ErrorResponse errorResponse;
Response.Status status;
if (exception instanceof BrandingPreferenceMgtClientException) {
errorResponse = getErrorBuilder(errorEnum, data).build(log, exception.getMessage());
if (exception.getErrorCode() != null) {
String errorCode = exception.getErrorCode();
errorCode = errorCode.contains(BRANDING_PREFERENCE_MGT_ERROR_CODE_DELIMITER) ? errorCode : BRANDING_PREFERENCE_ERROR_PREFIX + errorCode;
errorResponse.setCode(errorCode);
}
errorResponse.setDescription(exception.getMessage());
if (BRANDING_PREFERENCE_ALREADY_EXISTS_ERROR_CODE.equals(exception.getErrorCode())) {
status = Response.Status.CONFLICT;
} else if (BRANDING_PREFERENCE_NOT_EXISTS_ERROR_CODE.equals(exception.getErrorCode())) {
status = Response.Status.NOT_FOUND;
} else {
status = Response.Status.BAD_REQUEST;
}
} else if (exception instanceof BrandingPreferenceMgtServerException) {
errorResponse = getErrorBuilder(errorEnum, data).build(log, exception, errorEnum.getDescription());
if (exception.getErrorCode() != null) {
String errorCode = exception.getErrorCode();
errorCode = errorCode.contains(BRANDING_PREFERENCE_MGT_ERROR_CODE_DELIMITER) ? errorCode : BRANDING_PREFERENCE_ERROR_PREFIX + errorCode;
errorResponse.setCode(errorCode);
}
errorResponse.setDescription(exception.getMessage());
status = Response.Status.INTERNAL_SERVER_ERROR;
} else {
errorResponse = getErrorBuilder(errorEnum, data).build(log, exception, errorEnum.getDescription());
status = Response.Status.INTERNAL_SERVER_ERROR;
}
return new APIError(status, errorResponse);
}
Aggregations