From febc8733d2c4fce9d9d50105d8ccd6ce001c9444 Mon Sep 17 00:00:00 2001 From: "eyjhbb@gmail.com" Date: Tue, 5 May 2020 11:28:31 +0200 Subject: [PATCH] added error codes for pagination Signed-off-by: eyjhb --- registry/api/v2/descriptors.go | 12 ++++++++++++ registry/api/v2/errors.go | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/registry/api/v2/descriptors.go b/registry/api/v2/descriptors.go index 56bfdcdfb..1dbe68239 100644 --- a/registry/api/v2/descriptors.go +++ b/registry/api/v2/descriptors.go @@ -490,6 +490,18 @@ var routeDescriptors = []RouteDescriptor{ }, }, Failures: []ResponseDescriptor{ + { + Name: "Invalid pagination number", + Description: "The received parameter n was invalid in some way, as described by the error code. The client should resolve the issue and retry the request.", + StatusCode: http.StatusBadRequest, + Body: BodyDescriptor{ + ContentType: "application/json", + Format: errorsBody, + }, + ErrorCodes: []errcode.ErrorCode{ + ErrorCodePaginationNumberInvalid, + }, + }, unauthorizedResponseDescriptor, repositoryNotFoundResponseDescriptor, deniedResponseDescriptor, diff --git a/registry/api/v2/errors.go b/registry/api/v2/errors.go index c413efbb0..ac68af487 100644 --- a/registry/api/v2/errors.go +++ b/registry/api/v2/errors.go @@ -133,4 +133,14 @@ var ( longer proceed.`, HTTPStatusCode: http.StatusNotFound, }) + + // ErrorCodePaginationNumberInvalid is returned when the `n` parameter is + // not an integer, or `n` is negative. + ErrorCodePaginationNumberInvalid = errcode.Register(errGroup, errcode.ErrorDescriptor{ + Value: "PAGINATION_NUMBER_INVALID", + Message: "invalid number of results requested", + Description: `Returned when the "n" parameter (number of results + to return) is not an integer, or "n" is negative.`, + HTTPStatusCode: http.StatusBadRequest, + }) )