gogmagog/models/errors.go
Deepak 262321a1e2
All checks were successful
gitea-deepak/gogmagog/pipeline/head This commit looks good
Adds auth route that checks username and password
2021-01-12 12:43:45 -06:00

55 lines
1.0 KiB
Go

package models
import (
"database/sql"
"golang.org/x/crypto/bcrypt"
)
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
}
type invalidLoginError struct {
error
}
func (e *invalidLoginError) InvalidLogin() bool {
return true
}
// IsInvalidLoginError returns true if the model deems it an invalid login error.
func IsInvalidLoginError(err error) bool {
type invalidLogin interface {
InvalidLogin() bool
}
te, ok := err.(invalidLogin)
return ok && te.InvalidLogin()
}
func wrapInvalidLogin(err error) error {
if err == sql.ErrNoRows || err == bcrypt.ErrMismatchedHashAndPassword {
return &invalidLoginError{error: err}
}
return err
}