Class: Neetob::ExceptionHandler

Inherits:
CLI::Base show all
Defined in:
lib/neetob/exception_handler.rb

Constant Summary

Constants inherited from CLI::Base

CLI::Base::NEETO_APPS_LIST_LINK

Instance Attribute Summary collapse

Attributes inherited from CLI::Base

#ui

Instance Method Summary collapse

Methods included from Utils

#camel_case_to_slug, #is_upper?, #symbolize_keys

Constructor Details

#initialize(exception) ⇒ ExceptionHandler

Returns a new instance of ExceptionHandler.



9
10
11
12
# File 'lib/neetob/exception_handler.rb', line 9

def initialize(exception)
  super()
  @exception = exception
end

Instance Attribute Details

#exceptionObject

Returns the value of attribute exception.



7
8
9
# File 'lib/neetob/exception_handler.rb', line 7

def exception
  @exception
end

Instance Method Details

#processObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/neetob/exception_handler.rb', line 14

def process
  case exception
  when Thor::RequiredArgumentMissingError
    ui.error(
      "#{exception.message}."\
      " Please use the \"help\" command to check all the required options and try again."
    )
  when Octokit::NotFound
    ui.error(
      "#{exception.message}."\
      " Please check the repositry name, repositry access, API endpoint and try again."
    )
  when Octokit::UnprocessableEntity
    ui.error(
      "Failed to complete the given request."\
      " Make sure that the given entity is correct and processable")
  when Octokit::Unauthorized
    ui.error(
      "You are unauthorized to make API calls,"\
      " because the access token is either revoked or invalid or not set."\
      " Use \"neetob github login\" command to update or set the token.")
  when Octokit::Forbidden
    ui.error(
      "You don't have enough permissions to access 'bigbinary' organization."\
      " Please grant access to this org while authorizing via the browser.")
  when Errno::ENOENT
    ui.error(
      "#{exception.message}."\
      " Please check the given path and try again"
    )
  when JSON::ParserError
    ui.error(
      "There is a problem in parsing the JSON file."\
      " Please check and update the given JSON file."
    )
  when SystemExit
    ui.error(
      "Process exit with status code 1"
    )
  else
    ui.error(exception.message)
  end
end