Chore: Add errutils helpers (#73577)
Add helpers for the errutil package in favor of errutil.NewBase.
This commit is contained in:
@@ -41,6 +41,108 @@ func NewBase(reason StatusReason, msgID string, opts ...BaseOpt) Base {
|
||||
return b
|
||||
}
|
||||
|
||||
// NotFound initializes a new [Base] error with reason StatusNotFound
|
||||
// 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.notFound
|
||||
// plugin.notRegistered
|
||||
func NotFound(msgID string, opts ...BaseOpt) Base {
|
||||
return NewBase(StatusNotFound, 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.
|
||||
//
|
||||
// msgID should be structured as component.errorBrief, for example
|
||||
//
|
||||
// query.invalidDatasourceId
|
||||
// sse.dataQueryError
|
||||
func BadRequest(msgID string, opts ...BaseOpt) Base {
|
||||
return NewBase(StatusBadRequest, msgID, opts...)
|
||||
}
|
||||
|
||||
// ValidationFailed initializes a new [Base] error with reason StatusValidationFailed
|
||||
// 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
|
||||
//
|
||||
// datasource.nameInvalid
|
||||
// datasource.urlInvalid
|
||||
// serviceaccounts.errInvalidInput
|
||||
func ValidationFailed(msgID string, opts ...BaseOpt) Base {
|
||||
return NewBase(StatusValidationFailed, msgID, opts...)
|
||||
}
|
||||
|
||||
// Internal initializes a new [Base] error with reason StatusInternal
|
||||
// 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
|
||||
//
|
||||
// sqleng.connectionError
|
||||
// plugin.downstreamError
|
||||
func Internal(msgID string, opts ...BaseOpt) Base {
|
||||
return NewBase(StatusInternal, msgID, opts...)
|
||||
}
|
||||
|
||||
// Timeout initializes a new [Base] error with reason StatusTimeout.
|
||||
//
|
||||
// area.timeout
|
||||
func Timeout(msgID string, opts ...BaseOpt) Base {
|
||||
return NewBase(StatusTimeout, msgID, opts...)
|
||||
}
|
||||
|
||||
// Unauthorized initializes a new [Base] error with reason StatusUnauthorized
|
||||
// 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
|
||||
//
|
||||
// auth.unauthorized
|
||||
func Unauthorized(msgID string, opts ...BaseOpt) Base {
|
||||
return NewBase(StatusUnauthorized, msgID, opts...)
|
||||
}
|
||||
|
||||
// Forbidden initializes a new [Base] error with reason StatusForbidden
|
||||
// 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
|
||||
//
|
||||
// quota.disabled
|
||||
// user.sync.forbidden
|
||||
func Forbidden(msgID string, opts ...BaseOpt) Base {
|
||||
return NewBase(StatusForbidden, msgID, opts...)
|
||||
}
|
||||
|
||||
// TooManyRequests initializes a new [Base] error with reason StatusTooManyRequests
|
||||
// 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
|
||||
//
|
||||
// area.tooManyRequests
|
||||
func TooManyRequests(msgID string, opts ...BaseOpt) Base {
|
||||
return NewBase(StatusTooManyRequests, msgID, opts...)
|
||||
}
|
||||
|
||||
// NotImplemented initializes a new [Base] error with reason StatusNotImplemented
|
||||
// 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.notImplemented
|
||||
// auth.identity.unsupported
|
||||
func NotImplemented(msgID string, opts ...BaseOpt) Base {
|
||||
return NewBase(StatusNotImplemented, msgID, opts...)
|
||||
}
|
||||
|
||||
type BaseOpt func(Base) Base
|
||||
|
||||
// WithLogLevel sets a custom log level for all errors instantiated from
|
||||
|
||||
Reference in New Issue
Block a user