Monorepo for Tangled tangled.org

appview/xrpcclient: better errors

Signed-off-by: Anirudh Oppiliappan <anirudh@tangled.sh>

authored by anirudh.fi and committed by oppi.li ab2bd002 f0b92a26

Changed files
+11 -5
appview
xrpcclient
+11 -5
appview/xrpcclient/xrpc.go
··· 4 4 "bytes" 5 5 "context" 6 6 "errors" 7 - "fmt" 8 7 "io" 9 8 "net/http" 10 9 ··· 12 11 "github.com/bluesky-social/indigo/xrpc" 13 12 indigoxrpc "github.com/bluesky-social/indigo/xrpc" 14 13 oauth "tangled.sh/icyphox.sh/atproto-oauth" 14 + ) 15 + 16 + var ( 17 + ErrXrpcUnsupported = errors.New("xrpc not supported on this knot") 18 + ErrXrpcUnauthorized = errors.New("unauthorized xrpc request") 19 + ErrXrpcFailed = errors.New("xrpc request failed") 20 + ErrXrpcInvalid = errors.New("invalid xrpc request") 15 21 ) 16 22 17 23 type Client struct { ··· 115 121 116 122 var xrpcerr *indigoxrpc.Error 117 123 if ok := errors.As(err, &xrpcerr); !ok { 118 - return fmt.Errorf("Recieved invalid XRPC error response: %v", err) 124 + return ErrXrpcInvalid 119 125 } 120 126 121 127 switch xrpcerr.StatusCode { 122 128 case http.StatusNotFound: 123 - return fmt.Errorf("XRPC is unsupported on this knot, consider upgrading your knot.") 129 + return ErrXrpcUnsupported 124 130 case http.StatusUnauthorized: 125 - return fmt.Errorf("Unauthorized XRPC request.") 131 + return ErrXrpcUnauthorized 126 132 default: 127 - return fmt.Errorf("Failed to perform operation. Try again later.") 133 + return ErrXrpcFailed 128 134 } 129 135 }