From ab2bd00270e9284b98db4b935f3b9f3a4c54c9ef Mon Sep 17 00:00:00 2001 From: Anirudh Oppiliappan Date: Thu, 4 Sep 2025 14:25:37 +0300 Subject: [PATCH] appview/xrpcclient: better errors Signed-off-by: Anirudh Oppiliappan --- appview/xrpcclient/xrpc.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/appview/xrpcclient/xrpc.go b/appview/xrpcclient/xrpc.go index b0ad8377..2db9889e 100644 --- a/appview/xrpcclient/xrpc.go +++ b/appview/xrpcclient/xrpc.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "errors" - "fmt" "io" "net/http" @@ -14,6 +13,13 @@ import ( 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 { *oauth.XrpcClient authArgs *oauth.XrpcAuthedRequestArgs @@ -115,15 +121,15 @@ func HandleXrpcErr(err error) error { 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 } } -- 2.51.2