diff --git a/lib/entitlements/backend/github_team/service.rb b/lib/entitlements/backend/github_team/service.rb index 241ef0f..678f015 100644 --- a/lib/entitlements/backend/github_team/service.rb +++ b/lib/entitlements/backend/github_team/service.rb @@ -459,6 +459,11 @@ def add_user_to_team(user:, team:, role: "member") begin result = octokit.add_team_membership(team.team_id, user, role:) result[:state] == "active" || result[:state] == "pending" + rescue Octokit::UnprocessableEntity => e + raise e unless ignore_not_found && e.message =~ /Enterprise Managed Users must be part of the organization to be assigned to the team/ + + Entitlements.logger.warn "User #{user} not found in organization #{org}, ignoring." + false rescue Octokit::NotFound => e raise e unless ignore_not_found