Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 1 addition & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
xpm_ruby (0.4.0)
xpm_ruby (0.4.1)
activesupport
builder
dry-types
Expand Down Expand Up @@ -125,6 +125,3 @@ DEPENDENCIES
rubocop-rspec
vcr
xpm_ruby!

BUNDLED WITH
2.1.4
11 changes: 7 additions & 4 deletions lib/xpm_ruby/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -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",
Expand All @@ -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
Loading