From ab2bd00270e9284b98db4b935f3b9f3a4c54c9ef Mon Sep 17 00:00:00 2001 From: Anirudh Oppiliappan Date: Thu, 04 Sep 2025 11:25:37 +0000 Subject: [PATCH] appview/xrpcclient: better errors Signed-off-by: Anirudh Oppiliappan --- appview/xrpcclient/xrpc.go | 16 +++++++++++----- 1 file(s) changed, 11 insertion(s)(+), 5 deletion(s)(-) diff --git a/appview/xrpcclient/xrpc.go b/appview/xrpcclient/xrpc.go --- a/appview/xrpcclient/xrpc.go +++ b/appview/xrpcclient/xrpc.go @@ -4,7 +4,6 @@ "bytes" "context" "errors" - "fmt" "io" "net/http" @@ -12,6 +11,13 @@ "github.com/bluesky-social/indigo/xrpc" indigoxrpc "github.com/bluesky-social/indigo/xrpc" oauth "tangled.sh/icyphox.sh/atproto-oauth" +) + +var ( + ErrXrpcUnsupported = errors.New("xrpc not supported on this knot") + ErrXrpcUnauthorized = errors.New("unauthorized xrpc request") + ErrXrpcFailed = errors.New("xrpc request failed") + ErrXrpcInvalid = errors.New("invalid xrpc request") ) type Client struct { @@ -115,15 +121,15 @@ var xrpcerr *indigoxrpc.Error if ok := errors.As(err, &xrpcerr); !ok { - return fmt.Errorf("Recieved invalid XRPC error response: %v", err) + return ErrXrpcInvalid } switch xrpcerr.StatusCode { case http.StatusNotFound: - return fmt.Errorf("XRPC is unsupported on this knot, consider upgrading your knot.") + return ErrXrpcUnsupported case http.StatusUnauthorized: - return fmt.Errorf("Unauthorized XRPC request.") + return ErrXrpcUnauthorized default: - return fmt.Errorf("Failed to perform operation. Try again later.") + return ErrXrpcFailed } } -- tangled.sh