Beautified error messages
the build failed
Details
the build failed
Details
This commit is contained in:
parent
a734f21ac2
commit
068bfc942e
|
@ -19,7 +19,7 @@ sie in die Datenbank eingetragen und mit dem Buch verknüpft.
|
||||||
func AddOrUpdateBook(book Book) (newBook Book, err error) {
|
func AddOrUpdateBook(book Book) (newBook Book, err error) {
|
||||||
|
|
||||||
// Check if we have at least a booktitle when we're inserting a new book
|
// Check if we have at least a booktitle when we're inserting a new book
|
||||||
if book.Title == ""{
|
if book.Title == "" {
|
||||||
return Book{}, ErrBookTitleCannotBeEmpty{}
|
return Book{}, ErrBookTitleCannotBeEmpty{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,10 +37,10 @@ func (err ErrNoUsername) Error() string {
|
||||||
return fmt.Sprintf("you need to specify a username [user id: %d]", err.UserID)
|
return fmt.Sprintf("you need to specify a username [user id: %d]", err.UserID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrNoUsernamePassword represents a "UsernameAlreadyExists" kind of error.
|
// ErrNoUsernamePassword represents a "NoUsernamePassword" kind of error.
|
||||||
type ErrNoUsernamePassword struct {}
|
type ErrNoUsernamePassword struct{}
|
||||||
|
|
||||||
// IsErrNoUsernamePassword checks if an error is a ErrUsernameExists.
|
// IsErrNoUsernamePassword checks if an error is a ErrNoUsernamePassword.
|
||||||
func IsErrNoUsernamePassword(err error) bool {
|
func IsErrNoUsernamePassword(err error) bool {
|
||||||
_, ok := err.(ErrNoUsernamePassword)
|
_, ok := err.(ErrNoUsernamePassword)
|
||||||
return ok
|
return ok
|
||||||
|
@ -50,12 +50,12 @@ func (err ErrNoUsernamePassword) Error() string {
|
||||||
return fmt.Sprintf("you need to specify a username and a password")
|
return fmt.Sprintf("you need to specify a username and a password")
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrUserDoesNotExist represents a "UsernameAlreadyExists" kind of error.
|
// ErrUserDoesNotExist represents a "UserDoesNotExist" kind of error.
|
||||||
type ErrUserDoesNotExist struct {
|
type ErrUserDoesNotExist struct {
|
||||||
UserID int64
|
UserID int64
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsErrUserDoesNotExist checks if an error is a ErrUsernameExists.
|
// IsErrUserDoesNotExist checks if an error is a ErrUserDoesNotExist.
|
||||||
func IsErrUserDoesNotExist(err error) bool {
|
func IsErrUserDoesNotExist(err error) bool {
|
||||||
_, ok := err.(ErrUserDoesNotExist)
|
_, ok := err.(ErrUserDoesNotExist)
|
||||||
return ok
|
return ok
|
||||||
|
@ -65,10 +65,27 @@ func (err ErrUserDoesNotExist) Error() string {
|
||||||
return fmt.Sprintf("this user does not exist [user id: %d]", err.UserID)
|
return fmt.Sprintf("this user does not exist [user id: %d]", err.UserID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrIDCannotBeZero represents a "UsernameAlreadyExists" kind of error.
|
// ErrCouldNotGetUserID represents a "ErrCouldNotGetUserID" kind of error.
|
||||||
type ErrIDCannotBeZero struct {}
|
type ErrCouldNotGetUserID struct{}
|
||||||
|
|
||||||
// IsErrIDCannotBeZero checks if an error is a ErrUsernameExists.
|
// IsErrCouldNotGetUserID checks if an error is a ErrCouldNotGetUserID.
|
||||||
|
func IsErrCouldNotGetUserID(err error) bool {
|
||||||
|
_, ok := err.(ErrCouldNotGetUserID)
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func (err ErrCouldNotGetUserID) Error() string {
|
||||||
|
return fmt.Sprintf("could not get user ID")
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===================
|
||||||
|
// Empty things errors
|
||||||
|
// ===================
|
||||||
|
|
||||||
|
// ErrIDCannotBeZero represents a "IDCannotBeZero" kind of error. Used if an ID (of something, not defined) is 0 where it should not.
|
||||||
|
type ErrIDCannotBeZero struct{}
|
||||||
|
|
||||||
|
// IsErrIDCannotBeZero checks if an error is a ErrIDCannotBeZero.
|
||||||
func IsErrIDCannotBeZero(err error) bool {
|
func IsErrIDCannotBeZero(err error) bool {
|
||||||
_, ok := err.(ErrIDCannotBeZero)
|
_, ok := err.(ErrIDCannotBeZero)
|
||||||
return ok
|
return ok
|
||||||
|
@ -79,9 +96,9 @@ func (err ErrIDCannotBeZero) Error() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrAuthorCannotBeEmpty represents a "AuthorCannotBeEmpty" kind of error.
|
// ErrAuthorCannotBeEmpty represents a "AuthorCannotBeEmpty" kind of error.
|
||||||
type ErrAuthorCannotBeEmpty struct {}
|
type ErrAuthorCannotBeEmpty struct{}
|
||||||
|
|
||||||
// IsErrIDCannotBeZero checks if an error is a ErrUsernameExists.
|
// IsErrAuthorCannotBeEmpty checks if an error is a ErrAuthorCannotBeEmpty.
|
||||||
func IsErrAuthorCannotBeEmpty(err error) bool {
|
func IsErrAuthorCannotBeEmpty(err error) bool {
|
||||||
_, ok := err.(ErrAuthorCannotBeEmpty)
|
_, ok := err.(ErrAuthorCannotBeEmpty)
|
||||||
return ok
|
return ok
|
||||||
|
@ -92,7 +109,7 @@ func (err ErrAuthorCannotBeEmpty) Error() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrItemTitleCannotBeEmpty represents a "ErrItemTitleCannotBeEmpty" kind of error.
|
// ErrItemTitleCannotBeEmpty represents a "ErrItemTitleCannotBeEmpty" kind of error.
|
||||||
type ErrItemTitleCannotBeEmpty struct {}
|
type ErrItemTitleCannotBeEmpty struct{}
|
||||||
|
|
||||||
// IsErrItemTitleCannotBeEmpty checks if an error is a ErrItemTitleCannotBeEmpty.
|
// IsErrItemTitleCannotBeEmpty checks if an error is a ErrItemTitleCannotBeEmpty.
|
||||||
func IsErrItemTitleCannotBeEmpty(err error) bool {
|
func IsErrItemTitleCannotBeEmpty(err error) bool {
|
||||||
|
@ -105,9 +122,9 @@ func (err ErrItemTitleCannotBeEmpty) Error() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrBookTitleCannotBeEmpty represents a "ErrBookTitleCannotBeEmpty" kind of error.
|
// ErrBookTitleCannotBeEmpty represents a "ErrBookTitleCannotBeEmpty" kind of error.
|
||||||
type ErrBookTitleCannotBeEmpty struct {}
|
type ErrBookTitleCannotBeEmpty struct{}
|
||||||
|
|
||||||
// ErrBookTitleCannotBeEmpty checks if an error is a ErrBookTitleCannotBeEmpty.
|
// IsErrBookTitleCannotBeEmpty checks if an error is a ErrBookTitleCannotBeEmpty.
|
||||||
func IsErrBookTitleCannotBeEmpty(err error) bool {
|
func IsErrBookTitleCannotBeEmpty(err error) bool {
|
||||||
_, ok := err.(ErrBookTitleCannotBeEmpty)
|
_, ok := err.(ErrBookTitleCannotBeEmpty)
|
||||||
return ok
|
return ok
|
||||||
|
@ -117,21 +134,8 @@ func (err ErrBookTitleCannotBeEmpty) Error() string {
|
||||||
return fmt.Sprintf("the book should at least have a title")
|
return fmt.Sprintf("the book should at least have a title")
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrCouldNotGetUserID represents a "ErrCouldNotGetUserID" kind of error.
|
|
||||||
type ErrCouldNotGetUserID struct {}
|
|
||||||
|
|
||||||
// ErrBookTitleCannotBeEmpty checks if an error is a ErrBookTitleCannotBeEmpty.
|
|
||||||
func IsErrCouldNotGetUserID(err error) bool {
|
|
||||||
_, ok := err.(ErrCouldNotGetUserID)
|
|
||||||
return ok
|
|
||||||
}
|
|
||||||
|
|
||||||
func (err ErrCouldNotGetUserID) Error() string {
|
|
||||||
return fmt.Sprintf("could not get user ID")
|
|
||||||
}
|
|
||||||
|
|
||||||
// ErrNoPublisherName represents a "ErrNoPublisherName" kind of error.
|
// ErrNoPublisherName represents a "ErrNoPublisherName" kind of error.
|
||||||
type ErrNoPublisherName struct {}
|
type ErrNoPublisherName struct{}
|
||||||
|
|
||||||
// IsErrNoPublisherName checks if an error is a ErrNoPublisherName.
|
// IsErrNoPublisherName checks if an error is a ErrNoPublisherName.
|
||||||
func IsErrNoPublisherName(err error) bool {
|
func IsErrNoPublisherName(err error) bool {
|
||||||
|
|
|
@ -63,7 +63,7 @@ func AuthorAddOrUpdate(c echo.Context) error {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrAuthorCannotBeEmpty(err) {
|
if models.IsErrAuthorCannotBeEmpty(err) {
|
||||||
return c.JSON(http.StatusBadRequest, models.Message{"Id cannot be 0"})
|
return c.JSON(http.StatusBadRequest, models.Message{"Please provide at least a name and a lastname."})
|
||||||
}
|
}
|
||||||
return c.JSON(http.StatusInternalServerError, models.Message{"Error"})
|
return c.JSON(http.StatusInternalServerError, models.Message{"Error"})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue