use of org.wso2.carbon.stratos.common.exception.TenantManagementServerException in project identity-api-server by wso2.
the class ServerTenantManagementService method handleTenantManagementException.
/**
* Handle TenantMgtException, extract error code, error description and status code to be sent
* in the response.
*
* @param e TenantMgtException
* @param errorEnum Error Message information.
* @return APIError.
*/
private APIError handleTenantManagementException(TenantMgtException e, TenantManagementConstants.ErrorMessage errorEnum, String data) {
ErrorResponse errorResponse;
Response.Status status;
if (e instanceof TenantManagementClientException) {
if (ERROR_CODE_RESOURCE_LIMIT_REACHED.equals(e.getErrorCode())) {
return handleResourceLimitReached();
}
errorResponse = getErrorBuilder(errorEnum, data).build(log, e.getMessage());
if (e.getErrorCode() != null) {
String errorCode = e.getErrorCode();
errorResponse.setCode(errorCode);
}
errorResponse.setDescription(e.getMessage());
status = Response.Status.BAD_REQUEST;
} else if (e instanceof TenantManagementServerException) {
errorResponse = getErrorBuilder(errorEnum, data).build(log, e, errorEnum.getDescription());
if (e.getErrorCode() != null) {
String errorCode = e.getErrorCode();
errorResponse.setCode(errorCode);
}
errorResponse.setDescription(e.getMessage());
status = Response.Status.INTERNAL_SERVER_ERROR;
} else {
errorResponse = getErrorBuilder(errorEnum, data).build(log, e, errorEnum.getDescription());
status = Response.Status.INTERNAL_SERVER_ERROR;
}
return new APIError(status, errorResponse);
}
Aggregations