gorilla / rpc

Package gorilla/rpc is a golang foundation for RPC over HTTP services.
https://gorilla.github.io
BSD 3-Clause "New" or "Revised" License
595 stars 179 forks source link

Added optional error mapper to json2.Codec #63

Closed colega closed 5 years ago

colega commented 6 years ago

Application error mapping can't be done in the Service implementation, and it can't be a Server dependency, because error mapping depends on the codec being used: if we're using JSONRPC we'll want to map our errors to *json2.Error.

This introduces a new constructor for the codec, just to maintain the backwards-compatibility, NewCustomCodecWithErrorMapper, which accepts a simple function func(error) error. That one is passed to each CodecRequest, and if an error has to be returned and this function is not nil, we'll invoke it assigning the result to the error.