File: error.rb

package info (click to toggle)
ruby-vagrant-cloud 3.0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 408 kB
  • sloc: ruby: 4,343; makefile: 7
file content (48 lines) | stat: -rw-r--r-- 1,471 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
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
module VagrantCloud
  class Error < StandardError
    class ClientError < Error
      class RequestError < ClientError
        attr_accessor :error_code
        attr_accessor :error_arr

        def initialize(msg, http_body, http_code)
          message = msg

          begin
            errors = JSON.parse(http_body)
            if errors.is_a?(Hash)
              vagrant_cloud_msg = errors['errors']
              if vagrant_cloud_msg.is_a?(Array)
                message = msg + ' - ' + vagrant_cloud_msg.map(&:to_s).join(', ').to_s
              elsif !vagrant_cloud_msg.to_s.empty?
                message = msg + ' - ' + vagrant_cloud_msg.to_s
              end
            end
          rescue JSON::ParserError => err
            vagrant_cloud_msg = err.message
          end

          @error_arr = Array(vagrant_cloud_msg)
          @error_code = http_code.to_i
          super(message)
        end
      end

      class ConnectionLockedError < ClientError; end
    end

    class BoxError < Error
      class InvalidVersionError < BoxError
        def initialize(version_number)
          message = 'Invalid version given: ' + version_number
          super(message)
        end
      end
      class BoxExistsError < BoxError; end
      class ProviderNotFoundError < BoxError; end
      class VersionExistsError < BoxError; end
      class VersionStatusChangeError < BoxError; end
      class VersionProviderExistsError < BoxError; end
    end
  end
end