New errors API!!

This commit is contained in:
Manu Mtz-Almeida
2015-05-22 03:25:21 +02:00
parent 5f76ba2022
commit e94247f9ad
4 changed files with 107 additions and 100 deletions

View File

@ -10,19 +10,33 @@ import (
)
const (
ErrorTypeInternal = 1 << iota
ErrorTypeExternal = 1 << iota
ErrorTypeAny = 0xffffffff
ErrorTypeBind = 1 << 31
ErrorTypeRender = 1 << 30
ErrorTypePrivate = 1 << 0
ErrorTypePublic = 1 << 1
ErrorTypeAny = 0xffffffff
ErrorTypeNu = 2
)
// Used internally to collect errors that occurred during an http request.
type errorMsg struct {
Error error `json:"error"`
Flags int `json:"-"`
Meta interface{} `json:"meta"`
Error error `json:"error"`
Flags int `json:"-"`
Metadata interface{} `json:"meta"`
}
type errorMsgs []errorMsg
func (msg *errorMsg) Type(flags int) *errorMsg {
msg.Flags = flags
return msg
}
func (msg *errorMsg) Meta(data interface{}) *errorMsg {
msg.Metadata = data
return msg
}
type errorMsgs []*errorMsg
func (a errorMsgs) ByType(typ int) errorMsgs {
if len(a) == 0 {
@ -54,7 +68,7 @@ func (a errorMsgs) String() string {
}
var buffer bytes.Buffer
for i, msg := range a {
fmt.Fprintf(&buffer, "Error #%02d: %s\n Meta: %v\n", (i + 1), msg.Error, msg.Meta)
fmt.Fprintf(&buffer, "Error #%02d: %s\n Meta: %v\n", (i + 1), msg.Error, msg.Metadata)
}
return buffer.String()
}