Documentation ¶
Overview ¶
Package qberrors provides common errors to standardize error handling across Quickbae golang projects.
Index ¶
- Variables
- func HandleErrorJSON(err error) error
- func HandleErrorValidation(err error) error
- func InvalidInputError(err error, format string, a ...interface{}) error
- func IsSafe(err error) bool
- func NotFoundError(format string, a ...interface{}) error
- func SafeDetail(err error) string
- func SafeErrorf(err error, format string, a ...interface{}) error
- func SafeMessage(err error) string
- func StatusCode(err error) int
- func Upstream(err error) error
- type ErrClient
- type ErrInternal
- type ErrSafe
- type ErrService
- type Error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( BadRequest = ErrSafe{"bad request", http.StatusBadRequest} InvalidDataType = ErrSafe{"data type not valid", http.StatusBadRequest} InvalidInput = ErrSafe{"input not valid", http.StatusBadRequest} InvalidSyntax = ErrSafe{"syntax not valid", http.StatusBadRequest} NotFound = ErrSafe{"not found", http.StatusNotFound} )
ErrSafe errors.
Functions ¶
func HandleErrorJSON ¶
HandleErrorJSON handles a JSON unmarshaling error for input passed by a user by normalizing messages and returning either a ErrClient or ErrInternal.
func HandleErrorValidation ¶
HandleErrorValidation handles github.com/go-playground/validator validation errors for input passed by a user and returns an ErrClient.
func InvalidInputError ¶
InvalidInputError returns an ErrClient with ErrClient.safe set as BadRequest and additional context according to the format specifier.
func NotFoundError ¶
NotFoundError returns an ErrClient with ErrClient.safe set as NotFound and additional context according to the format specifier.
Example ¶
package main import ( "errors" "fmt" "github.com/QuickBase/quickbase-cli/qberrors" ) func main() { err := qberrors.NotFoundError("item %q", "123") if errors.Is(err, qberrors.NotFound) { fmt.Println(err) } }
Output: item "123": not found
func SafeDetail ¶
SafeDetail returns detail about the error that is safe for the user to see.
func SafeErrorf ¶
SafeErrorf returns a wrapped ErrSafe given the format specifier.
func SafeMessage ¶
SafeMessage returns an error message that is safe for the user to see.
func StatusCode ¶
StatusCode returns the status code associated with the error.
Types ¶
type ErrClient ¶
type ErrClient struct {
// contains filtered or unexported fields
}
ErrClient is an error due to client input. The operation should not be retried.
type ErrInternal ¶
type ErrInternal struct {
// contains filtered or unexported fields
}
ErrInternal is an error with the application. The operation should not be retried.
func (ErrInternal) Error ¶
func (e ErrInternal) Error() string
func (*ErrInternal) Safe ¶
func (e *ErrInternal) Safe(err error) error
Safe sets ErrInternal.safe as err. TODO add variadic argument that wraps err
func (*ErrInternal) Safef ¶
func (e *ErrInternal) Safef(err error, format string, a ...interface{}) error
Safef sets ErrInternal.safe as a wrapped err.
func (ErrInternal) Unwrap ¶
func (e ErrInternal) Unwrap() error
func (ErrInternal) Upstream ¶
func (e ErrInternal) Upstream() error
Upstream implements Error.Upstream.
type ErrSafe ¶
ErrSafe is an error that is assumed to be safe to show to the user. Errors that wrap ErrSafe are also assumed to be safe to show the user, inclusive of all subsequent wraps up the chain.
type ErrService ¶
type ErrService struct {
// contains filtered or unexported fields
}
ErrService is an error connecting to a dependent service. The operation can be retried.
func (ErrService) Error ¶
func (e ErrService) Error() string
func (*ErrService) Safe ¶
func (e *ErrService) Safe(err error) error
Safe sets ErrService.safe as err. TODO add variadic argument that wraps err
func (*ErrService) Safef ¶
func (e *ErrService) Safef(err error, format string, a ...interface{}) error
Safef sets ErrService.safe as a wrapped err.
func (ErrService) Unwrap ¶
func (e ErrService) Unwrap() error
func (ErrService) Upstream ¶
func (e ErrService) Upstream() error
Upstream implements Error.Upstream.