github.com/geniusesgroup/libgo@v0.0.0-20220713101832-828057a9d3d4/error/error.go (about) 1 /* For license and copyright information please see LEGAL file in repository */ 2 3 package error 4 5 import ( 6 "../mediatype" 7 "../protocol" 8 ) 9 10 // Error implements protocol.Error 11 // Never change MediaType due to it adds unnecessary complicated troubleshooting errors on SDK. 12 type Error struct { 13 internal bool 14 temporary bool 15 16 mediatype.MediaType 17 } 18 19 func (e *Error) Init(mediatype string) { 20 e.MediaType.Init(mediatype) 21 22 // RegisterError will register in the application. 23 // Force to check by runtime check, due to testing package not let us by any const! 24 if protocol.App != nil { 25 protocol.App.RegisterError(e) 26 } 27 } 28 29 // Equal compare two Error. 30 func (e *Error) Equal(err protocol.Error) bool { 31 if e == nil && err == nil { 32 return true 33 } 34 if e != nil && err != nil && e.ID() == err.ID() { 35 return true 36 } 37 return false 38 } 39 40 func (e *Error) Internal() bool { return e.internal } 41 func (e *Error) Temporary() bool { return e.temporary } 42 43 func (e *Error) SetInternal() { e.internal = true } 44 func (e *Error) SetTemporary() { e.temporary = true } 45 46 func (e *Error) Notify() { 47 // TODO::: 48 } 49 50 // Go compatibility methods. Unwrap provides compatibility for Go 1.13 error chains. 51 func (e *Error) Error() string { return e.ToString() } 52 func (e *Error) Cause() error { return e } 53 func (e *Error) Unwrap() error { return e }