This repository has been archived on 2026-09-07. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
sqaffold/error.go
T

51 lines
776 B
Go
Raw Normal View History

2026-09-01 00:13:01 +01:00
package sqaffold
import "net/http"
var (
ErrNoRows = NewError(http.StatusNotFound, "no rows", nil)
)
type Error struct {
StatusCode int
Text string
Previous error
}
func (e *Error) Error() string {
return e.Text
}
func (e *Error) Is(target error) bool {
if other, ok := target.(*Error); ok {
if other.StatusCode > 0 {
if e.StatusCode != other.StatusCode {
return false
}
}
if other.Text != "" {
if e.Text != other.Text {
return false
}
}
}
return true
}
func Err(err error) *Error {
return NewError(http.StatusInternalServerError, err.Error(), err)
}
func NewError(statusCode int, text string, previous error) *Error {
err := &Error{
StatusCode: statusCode,
Text: text,
Previous: previous,
}
return err
}