helper: Make `GrpcCode()` helper part of the `structerr` package
The structerr
package already handles gRPC error code propagation in
the way the helper.GrpcCode()
helper function does it: upon wrapping
an error with a preexisting error code we retain the code and propagate
it further up the error chain. As such, helper.GrpcCode()
duplicates
error code handling logic of the structerr
package.
Move the helper into the structerr
package and simplify its logic so
that it just builds on top of it. Instead of manually iterating through
the error chain and figuring out what the error code is supposed to be,
we now just unwrap the error to an error that implements GRPCStatus()
.
Like this we can either:
- See a `grpc/status.Status()` error. As these errors cannot wrap
any other errors anyway we have no other choice but to return its
error code.
- See a `structerr.Error`, which already knows to propagate error
codes up the callchain properly.
So in both cases we indeed retain the current semantics. This is the final part to convert our error handling to only use the structerr
package.