forked from zebresel-com/mongodm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
50 lines (38 loc) · 774 Bytes
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package mongodm
/*
err = User.FindId(user.Id, findUser)
if _, ok := err.(*mongodm.NotFoundError); ok {
log.W("DB: %v", err.Error())
} else if err != nil {
log.E("DB: %v", err)
}
*/
/*
Use this error type for checking if some records were found.
For example:
err := User.Find(bson.M{"firstname":"Paul"}).Populate("Messages").Exec(&users)
if _, ok := err.(*mongodm.NotFoundError); ok {
//no records were found
} else if err != nil {
//database error
}
*/
type QueryError struct {
message string
}
type NotFoundError struct {
*QueryError
}
type DuplicateError struct {
*QueryError
}
type ValidationError struct {
*QueryError
Errors []error
}
type InvalidIdError struct {
*QueryError
}
func (self *QueryError) Error() string {
return self.message
}