Something went wrong. Try again.
Monorepo for Tangled
Something went wrong. Try again.
754 B · 36 lines
Go
12345678910111213141516171819202122232425262728293031323334353637package xrpcclient
import ( "errors" "net/http"
indigoxrpc "github.com/bluesky-social/indigo/xrpc")
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"))
// produces a more manageable errorfunc HandleXrpcErr(err error) error { if err == nil { return nil }
var xrpcerr *indigoxrpc.Error if ok := errors.As(err, &xrpcerr); !ok { return ErrXrpcInvalid }
switch xrpcerr.StatusCode { case http.StatusNotFound: return ErrXrpcUnsupported case http.StatusUnauthorized: return ErrXrpcUnauthorized default: return ErrXrpcFailed }}