Commit 4f20ad1b authored by pbair's avatar pbair

Improve error message and minor clean up

Improve error message to display the type of relation the request has
failed for, to be clear to users that limitations are specific to the
type of results requested
parent dbb70c6c
......@@ -11,7 +11,7 @@ module API
end
end
def paginator(relation, request_scope)
def paginator(relation, request_scope = nil)
return keyset_paginator(relation) if keyset_pagination_enabled?
offset_paginator(relation, request_scope)
......@@ -31,8 +31,9 @@ module API
def offset_paginator(relation, request_scope)
offset_limit = limit_for_scope(request_scope)
if Gitlab::Pagination::Keyset.available_for_type?(relation) && offset_limit_exceeded?(offset_limit)
return error!("Offset pagination has a maximum allowed offset of #{offset_limit}, " \
"remaining records can be retrieved using keyset pagination.", 405)
return error!("Offset pagination has a maximum allowed offset of #{offset_limit} " \
"for requests that return objects of type #{relation.klass}. " \
"Remaining records can be retrieved using keyset pagination.", 405)
end
Gitlab::Pagination::OffsetPagination.new(self)
......
......@@ -3,8 +3,12 @@
module Gitlab
module Pagination
module Keyset
SUPPORTED_TYPES = [
Project
].freeze
def self.available_for_type?(relation)
relation.klass == Project
SUPPORTED_TYPES.include?(relation.klass)
end
def self.available?(request_context, relation)
......
......@@ -6,7 +6,7 @@ describe API::Helpers::PaginationStrategies do
subject { Class.new.include(described_class).new }
let(:expected_result) { double("result") }
let(:relation) { double("relation") }
let(:relation) { double("relation", klass: "SomeClass") }
let(:params) { {} }
before do
......@@ -90,7 +90,7 @@ describe API::Helpers::PaginationStrategies do
it 'renders a 405 error' do
expect(subject).to receive(:error!).with(/maximum allowed offset/, 405)
subject.paginator(relation, nil)
subject.paginator(relation)
end
end
......@@ -100,7 +100,7 @@ describe API::Helpers::PaginationStrategies do
it 'delegates to OffsetPagination' do
expect(Gitlab::Pagination::OffsetPagination).to receive(:new).with(subject).and_return(paginator)
expect(subject.paginator(relation, nil)).to eq(paginator)
expect(subject.paginator(relation)).to eq(paginator)
end
end
end
......@@ -116,7 +116,7 @@ describe API::Helpers::PaginationStrategies do
it 'delegates to OffsetPagination' do
expect(Gitlab::Pagination::OffsetPagination).to receive(:new).with(subject).and_return(paginator)
expect(subject.paginator(relation, nil)).to eq(paginator)
expect(subject.paginator(relation)).to eq(paginator)
end
end
end
......@@ -138,7 +138,7 @@ describe API::Helpers::PaginationStrategies do
end
it 'delegates to Pager' do
expect(subject.paginator(relation, nil)).to eq(pager)
expect(subject.paginator(relation)).to eq(pager)
end
end
......@@ -150,7 +150,7 @@ describe API::Helpers::PaginationStrategies do
it 'renders a 501 error' do
expect(subject).to receive(:error!).with(/not yet available/, 405)
subject.paginator(relation, nil)
subject.paginator(relation)
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment