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.
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.