Go library implementing a lightweight XRPC client for the AT Protocol.
atproto atprotocol lightweight xrpc
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(atproto): meta errors not working

anhgelus.world dd98a83f 12fc16ec

verified
+35 -41
+22
atproto/did.go
··· 231 231 return fmt.Sprintf("%s (status code: %d)", e.Message, e.StatusCode) 232 232 } 233 233 234 + func (e ErrDIDPlcResolve) Is(err error) bool { 235 + switch err.(type) { 236 + case ErrDIDPlcResolve: 237 + return true 238 + case ErrDIDNotFound: 239 + return e.StatusCode == http.StatusNotFound 240 + default: 241 + return false 242 + } 243 + } 244 + 234 245 func (e ErrDIDPlcResolve) As(target any) bool { 235 246 v, ok := target.(*ErrDIDNotFound) 236 247 if !ok || e.StatusCode == http.StatusNotFound { ··· 253 264 return fmt.Sprintf("invalid status code while fetching document: %d", e.StatusCode) 254 265 } 255 266 return fmt.Sprintf("%s (status code: %d)", e.Body, e.StatusCode) 267 + } 268 + 269 + func (e ErrDIDWebResolve) Is(err error) bool { 270 + switch err.(type) { 271 + case ErrDIDWebResolve: 272 + return true 273 + case ErrDIDNotFound: 274 + return e.StatusCode == http.StatusNotFound 275 + default: 276 + return false 277 + } 256 278 } 257 279 258 280 func (e ErrDIDWebResolve) As(target any) bool {
+2 -2
atproto/doc.go
··· 17 17 // 18 18 // # Errors 19 19 // 20 - // You can use [ErrCannotParse] to check if there is an error while parsing arguments. 20 + // You can use [IsErrCannotParse] to check if there is an error while parsing arguments. 21 21 // 22 22 // var err error 23 - // if errors.Is(err, atproto.ErrCannotParse{}) { 23 + // if atproto.IsErrCannotParse(err) { 24 24 // // err comes from an arg 25 25 // } 26 26 //
+11 -39
atproto/errors.go
··· 5 5 "net/http" 6 6 ) 7 7 8 - // ErrCannotParse is a generic error containing a cannot parse error like. 9 - // 10 - // See [AsCannotParse] to converts an error into [ErrCannotParse]. 11 - // The standard [errors.As] does not work: this is mainly a meta error. 12 - type ErrCannotParse struct { 13 - inner error 14 - } 15 - 16 - func (err ErrCannotParse) Error() string { 17 - return err.inner.Error() 18 - } 19 - 20 - func (err ErrCannotParse) Unwrap() error { 21 - return err.inner 22 - } 23 - 24 - func (err ErrCannotParse) Is(e error) bool { 25 - if _, ok := e.(ErrCannotParse); ok { 26 - return true 27 - } 28 - return errors.Is(e, ErrCannotParseHandle) || 29 - errors.Is(e, ErrCannotParseRecordKey) || 30 - errors.Is(e, ErrCannotParseURI) || 31 - errors.Is(e, ErrCannotParseCID) || 32 - errors.Is(e, ErrCannotParseDID) || 33 - errors.Is(e, ErrCannotParseNSID) || 34 - errors.Is(e, ErrCannotParseTID) || 35 - errors.Is(e, ErrCannotParseTime) 36 - } 37 - 38 - // AsCannotParse converts an error into [ErrCannotParse]. 39 - // 40 - // Panics if [ErrCannotParse.Is] returns false. 41 - func AsCannotParse(err error) ErrCannotParse { 42 - if !errors.Is(err, ErrCannotParse{}) { 43 - panic("cannot convert " + err.Error() + " to parse error") 44 - } 45 - return ErrCannotParse{err} 8 + // IsErrCannotParse returns true if the error is a cannot parse error like. 9 + func IsErrCannotParse(err error) bool { 10 + return errors.Is(err, ErrCannotParseHandle) || 11 + errors.Is(err, ErrCannotParseRecordKey) || 12 + errors.Is(err, ErrCannotParseURI) || 13 + errors.Is(err, ErrCannotParseCID) || 14 + errors.Is(err, ErrCannotParseDID) || 15 + errors.Is(err, ErrCannotParseNSID) || 16 + errors.Is(err, ErrCannotParseTID) || 17 + errors.Is(err, ErrCannotParseTime) 46 18 } 47 19 48 20 // ErrDIDNotFound indicates that the [DID] was not found. ··· 53 25 } 54 26 55 27 func (err ErrDIDNotFound) Error() string { 56 - return err.inner.Error() 28 + return "did not found: " + err.inner.Error() 57 29 } 58 30 59 31 func (err ErrDIDNotFound) Unwrap() error {