41 lines
602 B
Go
41 lines
602 B
Go
package errors
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
)
|
|
|
|
type Error struct {
|
|
Code int
|
|
Message string
|
|
}
|
|
|
|
func (e *Error) Error() string {
|
|
return fmt.Sprintf("code: %d, message: %s", e.Code, e.Message)
|
|
}
|
|
|
|
func Warp(code int, err error) error {
|
|
return &Error{
|
|
Code: code,
|
|
Message: err.Error(),
|
|
}
|
|
}
|
|
|
|
func Format(code int, msg string, args ...any) *Error {
|
|
return &Error{
|
|
Code: code,
|
|
Message: fmt.Sprintf(msg, args...),
|
|
}
|
|
}
|
|
|
|
func Is(err, target error) bool {
|
|
return errors.Is(err, target)
|
|
}
|
|
|
|
func New(code int, message string) *Error {
|
|
return &Error{
|
|
Code: code,
|
|
Message: message,
|
|
}
|
|
}
|