Closed kvuchkov closed 3 years ago
One can actually useyarpcerrors.Newf(yarpcerrors.CodeInvalidArgument, "%w", e)
to both wrap an internal error in YARPC status and set the desired code, since yarpcerrors.Newf
uses fmt.Errorf
internally when provided with arguments.
Thanks to @Dogild for the tip!
Problem Statement
I want to register a YARPC middleware that implements non-functional error handling logic, common for all service handlers, while still providing the YARPC status from the concrete handler.
I noticed that
yarpcerrors.Status
implements the idiomatic error wrapping. However, I am unable to instantiate ayarpcerrors.Status
while also settings the status code.Proposal
We can expose a
yarpcerrors.Wrap
very similar toyarpcerrors.Newf
that wraps an external error with a status code instead of creating a new error chain.