Skip to content

Commit fadc09a

Browse files
committed
rpc_proxy: add new wrapped error type
To add more context to an error happening in the proxy, we add a wrapped error type that adds more information about the origin of the error.
1 parent 9e7b01d commit fadc09a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

rpc_proxy.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@ const (
3333
HeaderMacaroon = "Macaroon"
3434
)
3535

36+
// proxyErr is an error type that adds more context to an error occurring in the
37+
// proxy.
38+
type proxyErr struct {
39+
wrapped error
40+
proxyContext string
41+
}
42+
43+
// Error returns the error message as a string, including the proxy's context.
44+
func (e *proxyErr) Error() string {
45+
return fmt.Sprintf("proxy error with context %s: %v", e.proxyContext,
46+
e.wrapped)
47+
}
48+
49+
// Unwrap returns the wrapped error.
50+
func (e *proxyErr) Unwrap() error {
51+
return e.wrapped
52+
}
53+
3654
// newRpcProxy creates a new RPC proxy that can take any native gRPC, grpc-web
3755
// or REST request and delegate (and convert if necessary) it to the correct
3856
// component.

0 commit comments

Comments
 (0)