Skip to content

Commit 8de5ad9

Browse files
Riley ShenkRiley Shenk
Riley Shenk
authored and
Riley Shenk
committed
Moved error handling method to its own file
1 parent ab1d7c8 commit 8de5ad9

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

error_handling.rb

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# The function that will be used for error handling
2+
3+
def check_response(response, message, error_handling = :fatal_error, interactive_mode = false)
4+
if !response["ok"]
5+
STDERR.puts "Error: \"#{response["error"]}\" - " + message
6+
if error_handling == :fatal_error
7+
exit 1
8+
end
9+
end
10+
end

invite.rb

+1-12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
require 'pp'
1515
require 'json'
1616
require "net/http"
17+
require './error_handling'
1718

1819
# hash to hold options given in the command line
1920
options = {:email => nil, :first_name => nil, :last_name => nil, :verbose => false, :api_key => nil}
@@ -61,16 +62,6 @@
6162
pp options
6263
end
6364

64-
# This method is used for error checking
65-
def check_response(response, message, error_handling = :fatal_error, interactive_mode = false)
66-
if !response["ok"]
67-
STDERR.puts "Error: \"#{response["error"]}\" - " + message
68-
if error_handling == :fatal_error
69-
exit 1
70-
end
71-
end
72-
end
73-
7465
# actually inviting the user
7566
method = "users.admin.invite?"
7667
slackHost = "https://slack.com/api/"
@@ -82,8 +73,6 @@ def check_response(response, message, error_handling = :fatal_error, interactive
8273
"email" => options[:email], "token" => options[:api_key], "first_name" => options[:first_name],
8374
"last_name" => options[:last_name], "set_active" => true).body)
8475
else
85-
puts "No"
86-
exit 1
8776
emailInviteResponse = JSON.parse(Net::HTTP.post_form(uri,
8877
"email" => options[:email], "token" => options[:api_key], "set_active" => true).body)
8978
end

0 commit comments

Comments
 (0)