Skip to content

Commit

Permalink
Raise error on empty paged responses (#252)
Browse files Browse the repository at this point in the history
* Raise error on empty paged responses

* Add ZeroPagesError as a new subclass of ClientError
  • Loading branch information
nanotone authored Mar 5, 2020
1 parent 9e4820a commit f374da6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/vbms/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ def initialize(cmd, output)
end
end

class ZeroPagesError < ClientError
end

class BadClaim < HTTPError; end
class BadPostalCode < HTTPError; end
class BadSOAPMessage < HTTPError; end
Expand Down
3 changes: 3 additions & 0 deletions lib/vbms/service/paged_documents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ def call(file_number:)
req = next_request(file_number, 0)
first_page = client.send_request(req)

# interpret a first page with no sections (and no doc count) as equivalent to zero pages.
raise ZeroPagesError.new("No sections found in first page") if first_page.empty?

# response will always be an array. get pagination from the first section.
(documents << first_page.map { |section| section[:documents] }).flatten!
pagination = first_page.first[:paging]
Expand Down
7 changes: 7 additions & 0 deletions spec/service/paged_documents_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,12 @@ def next_response
expect(r[:paging][:@total_result_count]).to eq total_docs
end
end

context "when the first page contains no sections" do
it "raises a ZeroPagesError" do
allow(client).to receive(:send_request).and_return []
expect { subject.call(file_number: file_number) }.to raise_error(VBMS::ZeroPagesError)
end
end
end
end

0 comments on commit f374da6

Please sign in to comment.