Module: Gitlang::Utilities

Included in:
Organization, Repository
Defined in:
lib/gitlang/utilities.rb

Overview

Contains general purpose methods.

Instance Method Summary collapse

Instance Method Details

#conditional_rescue { ... } ⇒ Object

Calls the given block and rescues from specific errors.

Examples:

conditional_rescue { @client.call }

Yields:

  • block



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/gitlang/utilities.rb', line 10

def conditional_rescue
  yield if block_given?
rescue Octokit::TooManyRequests
  raise Gitlang::GitlangError,
        'You made too many requests. Please set GITHUB_TOKEN.'
rescue Octokit::NotFound, URI::InvalidURIError
  raise Gitlang::GitlangError, 'Resource not found.'
rescue Octokit::Unauthorized
  raise Gitlang::GitlangError, 'Wrong GITHUB_TOKEN.'
rescue Faraday::ConnectionFailed
  raise Gitlang::GitlangError, 'Connection failed.'
end