use of org.wso2.carbon.identity.api.server.common.error.APIError in project identity-api-server by wso2.
the class ServerConfigManagementService method handleIdPException.
/**
* Handle IdentityProviderManagementException, extract error code, error description and status code to be sent
* in the response.
*
* @param e IdentityProviderManagementException.
* @param errorEnum Error Message information.
* @return APIError.
*/
private APIError handleIdPException(IdentityProviderManagementException e, Constants.ErrorMessage errorEnum, String data) {
ErrorResponse errorResponse;
Response.Status status;
if (e instanceof IdentityProviderManagementClientException) {
errorResponse = getErrorBuilder(errorEnum, data).build(log, e.getMessage());
if (e.getErrorCode() != null) {
String errorCode = e.getErrorCode();
errorCode = errorCode.contains(org.wso2.carbon.identity.api.server.common.Constants.ERROR_CODE_DELIMITER) ? errorCode : Constants.CONFIG_ERROR_PREFIX + errorCode;
errorResponse.setCode(errorCode);
}
errorResponse.setDescription(e.getMessage());
status = Response.Status.BAD_REQUEST;
} else if (e instanceof IdentityProviderManagementServerException) {
errorResponse = getErrorBuilder(errorEnum, data).build(log, e, errorEnum.description());
if (e.getErrorCode() != null) {
String errorCode = e.getErrorCode();
errorCode = errorCode.contains(org.wso2.carbon.identity.api.server.common.Constants.ERROR_CODE_DELIMITER) ? errorCode : Constants.CONFIG_ERROR_PREFIX + errorCode;
errorResponse.setCode(errorCode);
}
errorResponse.setDescription(e.getMessage());
status = Response.Status.INTERNAL_SERVER_ERROR;
} else {
errorResponse = getErrorBuilder(errorEnum, data).build(log, e, errorEnum.description());
status = Response.Status.INTERNAL_SERVER_ERROR;
}
return new APIError(status, errorResponse);
}
use of org.wso2.carbon.identity.api.server.common.error.APIError in project identity-api-server by wso2.
the class ServerEmailTemplatesService method handleI18nEmailMgtException.
/**
* Handle I18nEmailMgtException, i.e. extract error description from the exception and set to the
* API Error Response, along with an status code to be sent in the response.
*
* @param exception Exception thrown
* @param errorEnum Corresponding error enum
* @return API Error object.
*/
private APIError handleI18nEmailMgtException(I18nEmailMgtException exception, Constants.ErrorMessage errorEnum) {
ErrorResponse errorResponse;
Response.Status status;
if (exception instanceof I18nEmailMgtInternalException && Constants.getMappedErrorMessage(exception.getErrorCode()) != null) {
// Specific error with code is found.
Constants.ErrorMessage errorMessage = Constants.getMappedErrorMessage(exception.getErrorCode());
errorResponse = getErrorBuilder(errorMessage).build(log, exception, errorEnum.getDescription());
status = errorMessage.getHttpStatus();
} else if (exception instanceof I18nEmailMgtClientException) {
// Send client error with original exception message.
errorResponse = getErrorBuilder(errorEnum).build(log, exception.getMessage());
errorResponse.setDescription(exception.getMessage());
status = Response.Status.BAD_REQUEST;
} else {
// Server error
errorResponse = getErrorBuilder(errorEnum).build(log, exception, errorEnum.getDescription());
status = Response.Status.INTERNAL_SERVER_ERROR;
}
return new APIError(status, errorResponse);
}
use of org.wso2.carbon.identity.api.server.common.error.APIError in project identity-api-server by wso2.
the class ServerIdentityGovernanceService method handleNotImplementedCapabilities.
private void handleNotImplementedCapabilities(Integer limit, Integer offset, String filter, String sort) {
GovernanceConstants.ErrorMessage errorEnum = null;
if (limit != null) {
errorEnum = ERROR_CODE_PAGINATION_NOT_IMPLEMENTED;
} else if (offset != null) {
errorEnum = ERROR_CODE_PAGINATION_NOT_IMPLEMENTED;
} else if (filter != null) {
errorEnum = ERROR_CODE_FILTERING_NOT_IMPLEMENTED;
} else if (sort != null) {
errorEnum = ERROR_CODE_SORTING_NOT_IMPLEMENTED;
}
if (errorEnum != null) {
ErrorResponse errorResponse = getErrorBuilder(errorEnum).build(LOG, errorEnum.getDescription());
Response.Status status = Response.Status.NOT_IMPLEMENTED;
throw new APIError(status, errorResponse);
}
}
use of org.wso2.carbon.identity.api.server.common.error.APIError in project identity-api-server by wso2.
the class CORSService method handleCORSException.
private APIError handleCORSException(CORSManagementServiceException e, Constants.ErrorMessage errorEnum, String data) {
ErrorResponse errorResponse;
Response.Status status;
if (e instanceof CORSManagementServiceClientException) {
errorResponse = getErrorBuilder(errorEnum, data).build(log, e.getMessage());
if (e.getErrorCode() != null) {
String errorCode = e.getErrorCode();
errorCode = errorCode.contains(org.wso2.carbon.identity.api.server.common.Constants.ERROR_CODE_DELIMITER) ? errorCode : Constants.CORS_ERROR_PREFIX + errorCode;
errorResponse.setCode(errorCode);
}
errorResponse.setDescription(e.getMessage());
status = Response.Status.BAD_REQUEST;
} else if (e instanceof CORSManagementServiceServerException) {
errorResponse = getErrorBuilder(errorEnum, data).build(log, e, errorEnum.description());
if (e.getErrorCode() != null) {
String errorCode = e.getErrorCode();
errorCode = errorCode.contains(org.wso2.carbon.identity.api.server.common.Constants.ERROR_CODE_DELIMITER) ? errorCode : Constants.CORS_ERROR_PREFIX + errorCode;
errorResponse.setCode(errorCode);
}
errorResponse.setDescription(e.getMessage());
status = Response.Status.INTERNAL_SERVER_ERROR;
} else {
errorResponse = getErrorBuilder(errorEnum, data).build(log, e, errorEnum.description());
status = Response.Status.INTERNAL_SERVER_ERROR;
}
return new APIError(status, errorResponse);
}
use of org.wso2.carbon.identity.api.server.common.error.APIError in project identity-api-server by wso2.
the class ServerIdpManagementService method handleResourceLimitReached.
private APIError handleResourceLimitReached() {
ErrorResponse errorResponse = getErrorBuilder(ERROR_CODE_IDP_LIMIT_REACHED, null).build(log, ERROR_CODE_IDP_LIMIT_REACHED.getDescription());
Response.Status status = Response.Status.FORBIDDEN;
return new APIError(status, errorResponse);
}
Aggregations