Chore: use errutil for pluginRepo errors (#78647)
* Chore: use errutil for pluginRepo errors * Update pkg/util/errutil/status.go * Use errutil helper functions Co-Authored-By: Marcus Efraimsson <marcus.efraimsson@gmail.com> * Forgot the log level * Use entity --------- Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com>
This commit is contained in:
co-authored by
Marcus Efraimsson
parent
d64c2b6f4e
commit
ef2c79d22a
@@ -55,6 +55,28 @@ func NotFound(msgID string, opts ...BaseOpt) Base {
|
||||
return NewBase(StatusNotFound, msgID, opts...)
|
||||
}
|
||||
|
||||
// UnprocessableContent initializes a new [Base] error with reason StatusUnprocessableEntity
|
||||
// that is used to construct [Error]. The msgID is passed to the caller
|
||||
// to serve as the base for user facing error messages.
|
||||
//
|
||||
// msgID should be structured as component.errorBrief, for example
|
||||
//
|
||||
// plugin.checksumMismatch
|
||||
func UnprocessableEntity(msgID string, opts ...BaseOpt) Base {
|
||||
return NewBase(StatusUnprocessableEntity, msgID, opts...)
|
||||
}
|
||||
|
||||
// Conflict initializes a new [Base] error with reason StatusConflict
|
||||
// that is used to construct [Error]. The msgID is passed to the caller
|
||||
// to serve as the base for user facing error messages.
|
||||
//
|
||||
// msgID should be structured as component.errorBrief, for example
|
||||
//
|
||||
// folder.alreadyExists
|
||||
func Conflict(msgID string, opts ...BaseOpt) Base {
|
||||
return NewBase(StatusConflict, msgID, opts...)
|
||||
}
|
||||
|
||||
// BadRequest initializes a new [Base] error with reason StatusBadRequest
|
||||
// that is used to construct [Error]. The msgID is passed to the caller
|
||||
// to serve as the base for user facing error messages.
|
||||
|
||||
@@ -20,6 +20,15 @@ const (
|
||||
// corresponding document to return to the request.
|
||||
// HTTP status code 404.
|
||||
StatusNotFound CoreStatus = "Not found"
|
||||
// StatusUnprocessableEntity means that the server understands the request,
|
||||
// the content type and the syntax but it was unable to process the
|
||||
// contained instructions.
|
||||
// HTTP status code 422.
|
||||
StatusUnprocessableEntity CoreStatus = "Unprocessable Entity"
|
||||
// StatusConflict means that the server cannot fulfill the request
|
||||
// there is a conflict in the current state of a resource
|
||||
// HTTP status code 409.
|
||||
StatusConflict CoreStatus = "Conflict"
|
||||
// StatusTooManyRequests means that the client is rate limited
|
||||
// by the server and should back-off before trying again.
|
||||
// HTTP status code 429.
|
||||
@@ -92,6 +101,10 @@ func (s CoreStatus) HTTPStatus() int {
|
||||
return http.StatusNotFound
|
||||
case StatusTimeout, StatusGatewayTimeout:
|
||||
return http.StatusGatewayTimeout
|
||||
case StatusUnprocessableEntity:
|
||||
return http.StatusUnprocessableEntity
|
||||
case StatusConflict:
|
||||
return http.StatusConflict
|
||||
case StatusTooManyRequests:
|
||||
return http.StatusTooManyRequests
|
||||
case StatusBadRequest, StatusValidationFailed:
|
||||
@@ -120,6 +133,10 @@ func (s CoreStatus) LogLevel() LogLevel {
|
||||
return LevelInfo
|
||||
case StatusTimeout:
|
||||
return LevelInfo
|
||||
case StatusUnprocessableEntity:
|
||||
return LevelInfo
|
||||
case StatusConflict:
|
||||
return LevelInfo
|
||||
case StatusTooManyRequests:
|
||||
return LevelInfo
|
||||
case StatusBadRequest:
|
||||
|
||||
Reference in New Issue
Block a user