glia-errors 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/.ruby-version +1 -0
 - data/glia-errors.gemspec +1 -1
 - data/lib/glia/errors.rb +1 -0
 - data/lib/glia/errors/client_errors.rb +20 -4
 - data/lib/glia/errors/error.rb +7 -0
 - data/lib/glia/errors/error_types.rb +5 -0
 - data/lib/glia/errors/server_errors.rb +27 -0
 - metadata +5 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 603e9be432c9f317013ed3fb16c5861c75c844a3584d08ac3d4f39f1ba58ace4
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 7c88ac1f5d039ce62ec55f7ecb0ad4001138f48452a34d5697678c318873c753
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 737bc0b2593e79b79fb41c61bafe9ec2ef6b7d4deb9cd3175167fd5bcd30dcb79b4d85bf1c366f8fff5cd6a35ec75e76ce2903919da336bba4b53f118a2e4311
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: '0129e0df64a24f03a7b54d013f4c83b76ff1a66fd2e599fcdd7520859e45a4b68900e73a007e51042b171c9f4cbb391918dfdc6a49f9eabb96723ad1be50b245'
         
     | 
    
        data/.ruby-version
    ADDED
    
    | 
         @@ -0,0 +1 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ruby-2.7.2
         
     | 
    
        data/glia-errors.gemspec
    CHANGED
    
    
    
        data/lib/glia/errors.rb
    CHANGED
    
    
| 
         @@ -19,7 +19,7 @@ module Glia 
     | 
|
| 
       19 
19 
     | 
    
         
             
                    super(
         
     | 
| 
       20 
20 
     | 
    
         
             
                      type: INVALID_NUMBER_ERROR,
         
     | 
| 
       21 
21 
     | 
    
         
             
                      ref: "https://example.com/errors/#{INVALID_NUMBER_ERROR}.html",
         
     | 
| 
       22 
     | 
    
         
            -
                      message: "#{humanize(field)} " + (message || 'is invalid')
         
     | 
| 
      
 22 
     | 
    
         
            +
                      message: "#{humanize(field)} " + (message || 'value is invalid')
         
     | 
| 
       23 
23 
     | 
    
         
             
                    )
         
     | 
| 
       24 
24 
     | 
    
         
             
                  end
         
     | 
| 
       25 
25 
     | 
    
         
             
                end
         
     | 
| 
         @@ -29,7 +29,7 @@ module Glia 
     | 
|
| 
       29 
29 
     | 
    
         
             
                    super(
         
     | 
| 
       30 
30 
     | 
    
         
             
                      type: INVALID_VALUE_ERROR,
         
     | 
| 
       31 
31 
     | 
    
         
             
                      ref: "https://example.com/errors/#{INVALID_VALUE_ERROR}.html",
         
     | 
| 
       32 
     | 
    
         
            -
                      message: "#{humanize(field)} " + (message || 'is invalid')
         
     | 
| 
      
 32 
     | 
    
         
            +
                      message: "#{humanize(field)} " + (message || 'value is invalid')
         
     | 
| 
       33 
33 
     | 
    
         
             
                    )
         
     | 
| 
       34 
34 
     | 
    
         
             
                  end
         
     | 
| 
       35 
35 
     | 
    
         
             
                end
         
     | 
| 
         @@ -77,7 +77,8 @@ module Glia 
     | 
|
| 
       77 
77 
     | 
    
         
             
                    super(
         
     | 
| 
       78 
78 
     | 
    
         
             
                      type: INVALID_TYPE_ERROR,
         
     | 
| 
       79 
79 
     | 
    
         
             
                      ref: "https://example.com/errors/#{INVALID_TYPE_ERROR}.html",
         
     | 
| 
       80 
     | 
    
         
            -
                      message: "#{humanize(field)} " + (message || "must be of type #{type}")
         
     | 
| 
      
 80 
     | 
    
         
            +
                      message: "#{humanize(field)} " + (message || "must be of type #{type}"),
         
     | 
| 
      
 81 
     | 
    
         
            +
                      error_details: { type: type }
         
     | 
| 
       81 
82 
     | 
    
         
             
                    )
         
     | 
| 
       82 
83 
     | 
    
         
             
                  end
         
     | 
| 
       83 
84 
     | 
    
         
             
                end
         
     | 
| 
         @@ -104,6 +105,8 @@ module Glia 
     | 
|
| 
       104 
105 
     | 
    
         | 
| 
       105 
106 
     | 
    
         
             
                class ResourceNotFoundError < Error
         
     | 
| 
       106 
107 
     | 
    
         
             
                  def initialize(resource:, message: nil)
         
     | 
| 
      
 108 
     | 
    
         
            +
                    assert_snake_case(resource)
         
     | 
| 
      
 109 
     | 
    
         
            +
             
     | 
| 
       107 
110 
     | 
    
         
             
                    super(
         
     | 
| 
       108 
111 
     | 
    
         
             
                      type: RESOURCE_NOT_FOUND_ERROR,
         
     | 
| 
       109 
112 
     | 
    
         
             
                      ref: "https://example.com/errors/#{RESOURCE_NOT_FOUND_ERROR}.html",
         
     | 
| 
         @@ -115,6 +118,8 @@ module Glia 
     | 
|
| 
       115 
118 
     | 
    
         | 
| 
       116 
119 
     | 
    
         
             
                class NotVerifiedError < Error
         
     | 
| 
       117 
120 
     | 
    
         
             
                  def initialize(resource:, message: nil)
         
     | 
| 
      
 121 
     | 
    
         
            +
                    assert_snake_case(resource)
         
     | 
| 
      
 122 
     | 
    
         
            +
             
     | 
| 
       118 
123 
     | 
    
         
             
                    super(
         
     | 
| 
       119 
124 
     | 
    
         
             
                      type: NOT_VERIFIED_ERROR,
         
     | 
| 
       120 
125 
     | 
    
         
             
                      ref: "https://example.com/errors/#{NOT_VERIFIED_ERROR}.html",
         
     | 
| 
         @@ -126,6 +131,9 @@ module Glia 
     | 
|
| 
       126 
131 
     | 
    
         | 
| 
       127 
132 
     | 
    
         
             
                class RemainingAssociationError < Error
         
     | 
| 
       128 
133 
     | 
    
         
             
                  def initialize(resource:, associated_resource:, message: nil)
         
     | 
| 
      
 134 
     | 
    
         
            +
                    assert_snake_case(resource)
         
     | 
| 
      
 135 
     | 
    
         
            +
                    assert_snake_case(associated_resource)
         
     | 
| 
      
 136 
     | 
    
         
            +
             
     | 
| 
       129 
137 
     | 
    
         
             
                    default_message =
         
     | 
| 
       130 
138 
     | 
    
         
             
                      "cannot be modified/deleted because it is associated to one or more #{
         
     | 
| 
       131 
139 
     | 
    
         
             
                        humanize(associated_resource)
         
     | 
| 
         @@ -141,6 +149,8 @@ module Glia 
     | 
|
| 
       141 
149 
     | 
    
         | 
| 
       142 
150 
     | 
    
         
             
                class LimitExceededError < Error
         
     | 
| 
       143 
151 
     | 
    
         
             
                  def initialize(resource:, max:, message: nil)
         
     | 
| 
      
 152 
     | 
    
         
            +
                    assert_snake_case(resource)
         
     | 
| 
      
 153 
     | 
    
         
            +
             
     | 
| 
       144 
154 
     | 
    
         
             
                    super(
         
     | 
| 
       145 
155 
     | 
    
         
             
                      type: LIMIT_EXCEEDED_ERROR,
         
     | 
| 
       146 
156 
     | 
    
         
             
                      ref: "https://example.com/errors/#{LIMIT_EXCEEDED_ERROR}.html",
         
     | 
| 
         @@ -152,6 +162,8 @@ module Glia 
     | 
|
| 
       152 
162 
     | 
    
         | 
| 
       153 
163 
     | 
    
         
             
                class ResourceAlreadyExistsError < Error
         
     | 
| 
       154 
164 
     | 
    
         
             
                  def initialize(resource:, message: nil)
         
     | 
| 
      
 165 
     | 
    
         
            +
                    assert_snake_case(resource)
         
     | 
| 
      
 166 
     | 
    
         
            +
             
     | 
| 
       155 
167 
     | 
    
         
             
                    super(
         
     | 
| 
       156 
168 
     | 
    
         
             
                      type: RESOURCE_ALREADY_EXISTS_ERROR,
         
     | 
| 
       157 
169 
     | 
    
         
             
                      ref: "https://example.com/errors/#{RESOURCE_ALREADY_EXISTS_ERROR}.html",
         
     | 
| 
         @@ -163,6 +175,9 @@ module Glia 
     | 
|
| 
       163 
175 
     | 
    
         | 
| 
       164 
176 
     | 
    
         
             
                class InvalidResourceStateError < Error
         
     | 
| 
       165 
177 
     | 
    
         
             
                  def initialize(resource:, state:, message: nil)
         
     | 
| 
      
 178 
     | 
    
         
            +
                    assert_snake_case(resource)
         
     | 
| 
      
 179 
     | 
    
         
            +
                    assert_snake_case(state)
         
     | 
| 
      
 180 
     | 
    
         
            +
             
     | 
| 
       166 
181 
     | 
    
         
             
                    super(
         
     | 
| 
       167 
182 
     | 
    
         
             
                      type: INVALID_RESOURCE_STATE_ERROR,
         
     | 
| 
       168 
183 
     | 
    
         
             
                      ref: "https://example.com/errors/#{INVALID_RESOURCE_STATE_ERROR}.html",
         
     | 
| 
         @@ -186,7 +201,8 @@ module Glia 
     | 
|
| 
       186 
201 
     | 
    
         
             
                  def initialize(message: nil)
         
     | 
| 
       187 
202 
     | 
    
         
             
                    super(
         
     | 
| 
       188 
203 
     | 
    
         
             
                      type: RECIPIENT_OPTED_OUT_ERROR,
         
     | 
| 
       189 
     | 
    
         
            -
                      ref: 
     | 
| 
      
 204 
     | 
    
         
            +
                      ref:
         
     | 
| 
      
 205 
     | 
    
         
            +
                        'https://docs.glia.com/glia-dev/reference/webhooks#example-engagementrequestfailure-event-with-fail_error',
         
     | 
| 
       190 
206 
     | 
    
         
             
                      message: message || 'Recipient has opted out'
         
     | 
| 
       191 
207 
     | 
    
         
             
                    )
         
     | 
| 
       192 
208 
     | 
    
         
             
                  end
         
     | 
    
        data/lib/glia/errors/error.rb
    CHANGED
    
    | 
         @@ -4,6 +4,7 @@ module Glia 
     | 
|
| 
       4 
4 
     | 
    
         
             
              module Errors
         
     | 
| 
       5 
5 
     | 
    
         
             
                # Base error
         
     | 
| 
       6 
6 
     | 
    
         
             
                class Error
         
     | 
| 
      
 7 
     | 
    
         
            +
                  SNAKE_CASE_REGEX = /^[a-z0-9]+(_[a-z0-9]+)*$/.freeze
         
     | 
| 
       7 
8 
     | 
    
         
             
                  attr_reader :type, :ref, :message, :error_details
         
     | 
| 
       8 
9 
     | 
    
         | 
| 
       9 
10 
     | 
    
         
             
                  def initialize(type:, ref:, message: nil, error_details: nil)
         
     | 
| 
         @@ -46,6 +47,12 @@ module Glia 
     | 
|
| 
       46 
47 
     | 
    
         
             
                  def humanize(value)
         
     | 
| 
       47 
48 
     | 
    
         
             
                    value.to_s.capitalize.gsub('_', ' ')
         
     | 
| 
       48 
49 
     | 
    
         
             
                  end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                  def assert_snake_case(value)
         
     | 
| 
      
 52 
     | 
    
         
            +
                    return if value.to_s.match(SNAKE_CASE_REGEX)
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                    raise ArgumentError, "Expected '#{value}' to be in snake case"
         
     | 
| 
      
 55 
     | 
    
         
            +
                  end
         
     | 
| 
       49 
56 
     | 
    
         
             
                end
         
     | 
| 
       50 
57 
     | 
    
         
             
              end
         
     | 
| 
       51 
58 
     | 
    
         
             
            end
         
     | 
| 
         @@ -2,6 +2,7 @@ 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            module Glia
         
     | 
| 
       4 
4 
     | 
    
         
             
              module Errors
         
     | 
| 
      
 5 
     | 
    
         
            +
                # Client errors
         
     | 
| 
       5 
6 
     | 
    
         
             
                INPUT_VALIDATION_ERROR = 'input_validation_error'
         
     | 
| 
       6 
7 
     | 
    
         
             
                INVALID_TYPE_ERROR = 'invalid_type_error'
         
     | 
| 
       7 
8 
     | 
    
         
             
                INVALID_NUMBER_ERROR = 'invalid_number_error'
         
     | 
| 
         @@ -18,5 +19,9 @@ module Glia 
     | 
|
| 
       18 
19 
     | 
    
         
             
                INVALID_RESOURCE_STATE_ERROR = 'invalid_resource_state_error'
         
     | 
| 
       19 
20 
     | 
    
         
             
                AUTHORIZATION_ERROR = 'authorization_error'
         
     | 
| 
       20 
21 
     | 
    
         
             
                RECIPIENT_OPTED_OUT_ERROR = 'recipient_opted_out_error'
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                # Server errors
         
     | 
| 
      
 24 
     | 
    
         
            +
                INTERNAL_SERVER_ERROR = 'internal_server_error'
         
     | 
| 
      
 25 
     | 
    
         
            +
                SERVICE_UNAVAILABLE_ERROR = 'service_unavailable_error'
         
     | 
| 
       21 
26 
     | 
    
         
             
              end
         
     | 
| 
       22 
27 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,27 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module Glia
         
     | 
| 
      
 4 
     | 
    
         
            +
              module Errors
         
     | 
| 
      
 5 
     | 
    
         
            +
                # rubocop:disable Style/Documentation
         
     | 
| 
      
 6 
     | 
    
         
            +
                class InternalServerError < Error
         
     | 
| 
      
 7 
     | 
    
         
            +
                  def initialize(message: nil)
         
     | 
| 
      
 8 
     | 
    
         
            +
                    super(
         
     | 
| 
      
 9 
     | 
    
         
            +
                      type: INTERNAL_SERVER_ERROR,
         
     | 
| 
      
 10 
     | 
    
         
            +
                      ref: "https://example.com/errors/#{INTERNAL_SERVER_ERROR}.html",
         
     | 
| 
      
 11 
     | 
    
         
            +
                      message: message || 'Internal server error'
         
     | 
| 
      
 12 
     | 
    
         
            +
                    )
         
     | 
| 
      
 13 
     | 
    
         
            +
                  end
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                class ServiceUnavailableError < Error
         
     | 
| 
      
 17 
     | 
    
         
            +
                  def initialize(message: nil)
         
     | 
| 
      
 18 
     | 
    
         
            +
                    super(
         
     | 
| 
      
 19 
     | 
    
         
            +
                      type: SERVICE_UNAVAILABLE_ERROR,
         
     | 
| 
      
 20 
     | 
    
         
            +
                      ref: "https://example.com/errors/#{SERVICE_UNAVAILABLE_ERROR}.html",
         
     | 
| 
      
 21 
     | 
    
         
            +
                      message: message || 'Service unavailable'
         
     | 
| 
      
 22 
     | 
    
         
            +
                    )
         
     | 
| 
      
 23 
     | 
    
         
            +
                  end
         
     | 
| 
      
 24 
     | 
    
         
            +
                end
         
     | 
| 
      
 25 
     | 
    
         
            +
                # rubocop:enable Style/Documentation
         
     | 
| 
      
 26 
     | 
    
         
            +
              end
         
     | 
| 
      
 27 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: glia-errors
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.5. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.5.1
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Glia TechMovers
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire:
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2021-02 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2021-03-02 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies: []
         
     | 
| 
       13 
13 
     | 
    
         
             
            description: ''
         
     | 
| 
       14 
14 
     | 
    
         
             
            email:
         
     | 
| 
         @@ -22,6 +22,7 @@ files: 
     | 
|
| 
       22 
22 
     | 
    
         
             
            - ".prettierrc"
         
     | 
| 
       23 
23 
     | 
    
         
             
            - ".rspec"
         
     | 
| 
       24 
24 
     | 
    
         
             
            - ".rubocop.yml"
         
     | 
| 
      
 25 
     | 
    
         
            +
            - ".ruby-version"
         
     | 
| 
       25 
26 
     | 
    
         
             
            - ".travis.yml"
         
     | 
| 
       26 
27 
     | 
    
         
             
            - Appraisals
         
     | 
| 
       27 
28 
     | 
    
         
             
            - Gemfile
         
     | 
| 
         @@ -36,6 +37,7 @@ files: 
     | 
|
| 
       36 
37 
     | 
    
         
             
            - lib/glia/errors/error.rb
         
     | 
| 
       37 
38 
     | 
    
         
             
            - lib/glia/errors/error_types.rb
         
     | 
| 
       38 
39 
     | 
    
         
             
            - lib/glia/errors/mapper.rb
         
     | 
| 
      
 40 
     | 
    
         
            +
            - lib/glia/errors/server_errors.rb
         
     | 
| 
       39 
41 
     | 
    
         
             
            homepage:
         
     | 
| 
       40 
42 
     | 
    
         
             
            licenses:
         
     | 
| 
       41 
43 
     | 
    
         
             
            - MIT
         
     | 
| 
         @@ -55,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       55 
57 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       56 
58 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       57 
59 
     | 
    
         
             
            requirements: []
         
     | 
| 
       58 
     | 
    
         
            -
            rubygems_version: 3. 
     | 
| 
      
 60 
     | 
    
         
            +
            rubygems_version: 3.1.4
         
     | 
| 
       59 
61 
     | 
    
         
             
            signing_key:
         
     | 
| 
       60 
62 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       61 
63 
     | 
    
         
             
            summary: Glia REST API errors
         
     |