Skip to content

Commit 686c9d1

Browse files
committed
Add error responses handling
1 parent 4caf485 commit 686c9d1

File tree

2 files changed

+13
-21
lines changed

2 files changed

+13
-21
lines changed

assertthat-bdd.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |s|
22
s.name = %q{assertthat-bdd}
3-
s.version = "1.5.0"
3+
s.version = "1.6.1"
44
s.date = %q{2020-05-08}
55
s.summary = %q{AssertThat bdd integration for Ruby}
66
s.authors = ["Glib Briia"]

lib/assertthat-bdd.rb

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,21 @@ module AssertThatBDD
77
class Features
88
def self.download(accessKey: ENV['ASSERTTHAT_ACCESS_KEY'], secretKey: ENV['ASSERTTHAT_ACCESS_KEY'], projectId: nil, outputFolder: './features/', proxy: nil, mode: 'automated', jql: '', tags: '', jiraServerUrl: nil)
99
RestClient.proxy = proxy unless proxy.nil?
10-
url = ['https://heavy-bat-23.loca.lt/rest/api/1/project/', projectId, '/features'].map(&:to_s).join('')
10+
url = ['https://bdd.assertthat.app/rest/api/1/project/', projectId, '/features'].map(&:to_s).join('')
1111
url = [jiraServerUrl,"/rest/assertthat/latest/project/",projectId,"/client/features"].map(&:to_s).join('') unless jiraServerUrl.nil?
1212
resource = RestClient::Resource.new(url, :user => accessKey, :password => secretKey, :content_type => 'application/zip')
13-
begin
1413
resource.get(:accept => 'application/zip', params: {mode: mode, jql: jql, tags: tags}) do |response, request, result|
14+
case response.code
15+
when 401
16+
puts '*** ERROR: Unauthorized error (401). Supplied secretKey/accessKey is invalid'
17+
return
18+
when 400
19+
puts '*** ERROR: ' + e.response
20+
return
21+
when 500
22+
puts '*** ERROR: Jira server error (500)'
23+
return
24+
end
1525
Dir.mkdir("#{outputFolder}") unless File.exists?("#{outputFolder}")
1626
File.open("#{outputFolder}/features.zip", 'wb') {|f| f.write(response) }
1727
features_count = 0
@@ -27,24 +37,6 @@ def self.download(accessKey: ENV['ASSERTTHAT_ACCESS_KEY'], secretKey: ENV['ASSER
2737
puts "*** INFO: #{features_count} features downloaded"
2838
end
2939
File.delete("#{outputFolder}/features.zip")
30-
rescue => e
31-
32-
if e.respond_to?('response') then
33-
if e.response.respond_to?('code') then
34-
case e.response.code
35-
when 401
36-
puts '*** ERROR: Unauthorized error (401). Supplied secretKey/accessKey is invalid'
37-
when 400
38-
puts '*** ERROR: ' + e.response
39-
when 500
40-
puts '*** ERROR: Jira server error (500)'
41-
end
42-
end
43-
else
44-
puts '*** ERROR: Failed download features: ' + e.message
45-
end
46-
return
47-
end
4840
end
4941
end
5042
end

0 commit comments

Comments
 (0)