diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 074b4c4..1422d59 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -12,14 +12,14 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up Ruby 3.1 - uses: actions/setup-ruby@v1 + - uses: actions/checkout@v4 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 with: - ruby-version: 3.1.x - - name: Build and test with Rake - run: | - gem install bundler - bundle install --jobs 4 --retry 3 - bundle exec rubocop - bundle exec rake + ruby-version: '3.1' + bundler: latest + bundler-cache: true + - name: Lint + run: bundle exec rubocop + - name: Test + run: bundle exec rake diff --git a/Gemfile.lock b/Gemfile.lock index 9717cbb..b71d2f0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - xpm_ruby (0.4.0) + xpm_ruby (0.4.1) activesupport builder dry-types @@ -125,6 +125,3 @@ DEPENDENCIES rubocop-rspec vcr xpm_ruby! - -BUNDLED WITH - 2.1.4 diff --git a/lib/xpm_ruby/connection.rb b/lib/xpm_ruby/connection.rb index 0691ab6..6af8700 100644 --- a/lib/xpm_ruby/connection.rb +++ b/lib/xpm_ruby/connection.rb @@ -71,7 +71,7 @@ def xpm_url def handle_response(response) case response.status when 401 - detail = JSON.parse(response.body)["Detail"] + detail = error_detail(response) case detail when /TokenExpired: token expired/ @@ -80,15 +80,14 @@ def handle_response(response) raise Unauthorized.new(detail) end when 403 # this can happen with a bad xero_tenant_id - detail = JSON.parse(response.body)["Detail"] + detail = error_detail(response) raise AuthenticationUnsuccessful.new(detail) if detail == "AuthenticationUnsuccessful" raise Forbidden.new(detail) when 500 raise InternalServerError.new(response.reason_phrase) when 503 - detail = JSON.parse(response.body)["Detail"] - raise NotAvailable.new(detail) + raise NotAvailable.new(error_detail(response)) when 429 # rate limit exceeded details = response.headers.slice( "retry-after", @@ -111,5 +110,9 @@ def handle_response(response) raise UnknownError.new(response.status) end end + + def error_detail(response) + JSON.parse(response.body)["Detail"] + end end end