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