lib/embulk/input/jira_api/client.rb in embulk-input-jira-0.2.2 vs lib/embulk/input/jira_api/client.rb in embulk-input-jira-0.2.3
- old
+ new
@@ -38,10 +38,23 @@
def total_count(jql)
search(jql, max_results: 1).num_results
end
+ def check_user_credential(username)
+ Jiralicious::Issue.find(username)
+ rescue Jiralicious::JqlError, Jiralicious::AuthenticationError, Jiralicious::NotLoggedIn, Jiralicious::InvalidLogin => e
+ raise Embulk::ConfigError.new(e.message)
+ rescue ::SocketError => e
+ # wrong `uri` option given
+ raise Embulk::ConfigError.new(e.message)
+ rescue MultiJson::ParseError => e
+ html = e.message
+ title = html[%r|<title>(.*?)</title>|, 1] #=> e.g. "Unauthorized (401)"
+ raise ConfigError.new("Can not authorize with your credential.") if title == 'Unauthorized (401)'
+ end
+
private
def timeout_and_retry(wait, retry_times = DEFAULT_SEARCH_RETRY_TIMES, &block)
count = 1
begin
@@ -59,16 +72,15 @@
# And (b) `search_issues` method has race-condition bug. If it occurred, MultiJson::ParseError raised too.
html = e.message
title = html[%r|<title>(.*?)</title>|, 1] #=> e.g. "Unauthorized (401)"
if title
# (a)
- Embulk.logger.warn "JIRA returns HTML: #{html}"
case title
when "Atlassian Cloud Notifications - Page Unavailable"
# a.k.a. HTTP 503
raise title
when "Unauthorized (401)"
- Embulk.logger.warn "JIRA returns error: #{title}"
+ Embulk.logger.warn "JIRA returns error: #{title}. Will go to retry"
count += 1
retry
end
else
# (b)