mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Render pagination errors
This commit is contained in:
@@ -17,6 +17,7 @@ module Api
|
||||
rescue_from Exception, with: :error_during_processing
|
||||
rescue_from CanCan::AccessDenied, with: :unauthorized
|
||||
rescue_from ActiveRecord::RecordNotFound, with: :not_found
|
||||
rescue_from Pagy::VariableError, with: :invalid_pagination
|
||||
|
||||
private
|
||||
|
||||
@@ -49,6 +50,11 @@ module Api
|
||||
json: json_api_error(exception.message, backtrace: exception.backtrace)
|
||||
end
|
||||
|
||||
def invalid_pagination(exception)
|
||||
render status: :unprocessable_entity,
|
||||
json: json_api_error(exception.message)
|
||||
end
|
||||
|
||||
def invalid_resource!(resource = nil)
|
||||
render status: :unprocessable_entity,
|
||||
json: json_api_invalid(
|
||||
|
||||
@@ -81,6 +81,17 @@ describe "Customers", type: :request do
|
||||
get "/api/v1/customers", params: { page: "2", per_page: "1" }
|
||||
expect(json_response_ids).to eq [customer2.id.to_s]
|
||||
end
|
||||
|
||||
it "renders beyond the available pages" do
|
||||
get "/api/v1/customers", params: { page: "2" }
|
||||
expect(json_response_ids).to eq []
|
||||
end
|
||||
|
||||
it "informs about invalid pages" do
|
||||
get "/api/v1/customers", params: { page: "0" }
|
||||
expect(json_response_ids).to eq nil
|
||||
expect(json_error_detail).to eq 'expected :page >= 1; got "0"'
|
||||
end
|
||||
end
|
||||
|
||||
post "Create customer" do
|
||||
|
||||
Reference in New Issue
Block a user