gorilla/rpc — pull request #19 by rjeczalik (2013-09-30 22:12:16+00:00)
Title: json v1 client/server: make it possible to pass JSON in an error field

Hi again,

I've extended an error field serialization both on client/server side for json1 (v2/json). The overall idea is to make it possible for a server to return error as a JSON object, and for client - to read one as such. I took the same approach as we have right now in json2, that is in order to respond with a JSON error a handler func needs to return a *json.Error struct; on the other hand in order to read JSON on the client side one must use type assertion on the error returned by `DecodeClientResponse` function. (In future it may be appropriate to add one more utility func to do it more elegantly, `DecodeClientResponseError(r io.Reader, reply interface{}, err interface{}) (bool, error)` or so, but it's just a digression for now).

One thing that I'm not 100% sure is the json.Error object itself, specifically the name of a interface{} member which holds unmashalled JSON value. (I had an use-case in which naming it after Data [the same name as optional auxiliary field of a JSON2 error object] made it easier for me to handle both JSON- and JSON2- errors in elegant way by using reflection).

If you've any comments I'd be happy to address them.