refactor(error): error handling in database package
- Replace custom error types with string constants for common database errors. - Simplify the Database struct to include a Reason field for error messages. - Update Error method to format the error output using the Reason. - Modify validation error constants for consistency and clarity.
This commit is contained in:
parent
fefc777888
commit
b8e29de4fc
@ -1,25 +1,19 @@
|
||||
package error
|
||||
|
||||
type EntityAlreadyExists struct{}
|
||||
import "fmt"
|
||||
|
||||
func (e *EntityAlreadyExists) Error() string {
|
||||
return "EntityAlreadyExists error"
|
||||
const (
|
||||
EntityAlreadyExists = "EntityAlreadyExists"
|
||||
NoDataWritten = "NoDataWritten"
|
||||
NoDataFound = "NoDataFound"
|
||||
DatabaseIsNotConnected = "database is not connected"
|
||||
DuplicateKey = "DuplicateKey"
|
||||
)
|
||||
|
||||
type Database struct {
|
||||
Reason string
|
||||
}
|
||||
|
||||
type NoDataWritten struct{}
|
||||
|
||||
func (e *NoDataWritten) Error() string {
|
||||
return "NoDataWritten error"
|
||||
}
|
||||
|
||||
type NoDataFound struct{}
|
||||
|
||||
func (e *NoDataFound) Error() string {
|
||||
return "NoDataFound error"
|
||||
}
|
||||
|
||||
type NoRelationCreated struct{}
|
||||
|
||||
func (e *NoRelationCreated) Error() string {
|
||||
return "relationship creation error"
|
||||
func (e Database) Error() string {
|
||||
return fmt.Sprintf("Database error: %s", e.Reason)
|
||||
}
|
||||
|
@ -3,11 +3,13 @@ package error
|
||||
import "fmt"
|
||||
|
||||
const (
|
||||
AnthroveUserIDIsEmpty = "anthrovePostID cannot be empty"
|
||||
AnthroveUserIDToShort = "anthrovePostID needs to be 25 characters long"
|
||||
AnthroveSourceIDEmpty = "anthroveSourceID cannot be empty"
|
||||
AnthroveSourceIDToShort = "anthroveSourceID needs to be 25 characters long"
|
||||
AnthroveTagIDEmpty = "tagID cannot be empty"
|
||||
UserIDIsEmpty = "anthrovePostID cannot be empty"
|
||||
UserIDToShort = "anthrovePostID needs to be 25 characters long"
|
||||
SourceIDEmpty = "anthroveSourceID cannot be empty"
|
||||
SourceIDToShort = "anthroveSourceID needs to be 25 characters long"
|
||||
UserSourceIDEmpty = "anthroveUserSourceID cannot be empty"
|
||||
UserSourceIDToShort = "anthroveUserSourceID needs to be 25 characters long"
|
||||
TagIDEmpty = "tagID cannot be empty"
|
||||
)
|
||||
|
||||
type EntityValidationFailed struct {
|
||||
|
Loading…
Reference in New Issue
Block a user