github.com/alloyzeus/go-azfl@v0.0.0-20231220071816-9740126a2d07/errors/access/errors.go (about) 1 // Package access is deprecated. 2 package access 3 4 import ( 5 "github.com/alloyzeus/go-azfl/errors" 6 ) 7 8 // Error is an abstract error type for all API access-related errors. 9 type Error interface { 10 errors.CallError 11 AccessError() Error 12 } 13 14 // New creates an API access-error which wraps another error. 15 func New(innerErr error) Error { 16 return &errorWrap{innerErr} 17 } 18 19 // Msg creates an API access-error which wraps simple message error. 20 func Msg(errMsg string) Error { 21 return &errorWrap{errors.New(errMsg)} 22 } 23 24 // Wrap creates an API access-error which provides additional context 25 // to another error. 26 func Wrap(contextMsg string, causeErr error) Error { 27 return &errorWrap{errors.Wrap(contextMsg, causeErr)} 28 } 29 30 var ( 31 _ Error = &errorWrap{} 32 _ errors.Unwrappable = &errorWrap{} 33 _ errors.CallError = &errorWrap{} 34 ) 35 36 type errorWrap struct { 37 innerErr error 38 } 39 40 func (e *errorWrap) Error() string { 41 if e.innerErr != nil { 42 return e.innerErr.Error() 43 } 44 return "access error" 45 } 46 47 func (e *errorWrap) Unwrap() error { 48 return e.innerErr 49 } 50 51 func (e *errorWrap) CallError() errors.CallError { return e } 52 func (e *errorWrap) AccessError() Error { return e }