gogmagog/models/errors.go
Deepak bbb0cf3f42
All checks were successful
gitea-deepak/gogmagog/pipeline/head This commit looks good
Adds way to check for not found error on id search
2021-01-01 08:07:55 -06:00

30 lines
474 B
Go

package models
import (
"database/sql"
)
type notFoundError struct {
error
}
func (e *notFoundError) NotFound() bool {
return true
}
// IsNotFoundError returns true if the model deems it a not found error.
func IsNotFoundError(err error) bool {
type notFound interface {
NotFound() bool
}
te, ok := err.(notFound)
return ok && te.NotFound()
}
func wrapNotFound(err error) error {
if err == sql.ErrNoRows {
return &notFoundError{error: err}
}
return err
}