Closed firepear closed 8 years ago
Original plan was to send PERRPERR{error data}
but JSON is unnecessarily heavy on processing and allocation. Will use ::
to separate fields in error, as in PERRPERR402::error msg
Can use bytes.HasPrefix
to test for response beginning with PERRPERR
Ditching the ::
is possible because the format is invariable anyway. PERRPERRXXXMESSAGE
Several things need to happen.
err
to returning a string
. The string will either be null, or not, in which case it is a key to the perrs
map. This is actually the same as returning an err, since if the string is not null we're going into error handling.perr
created for itperr
has an error
in it, which will almost always be used as a string. It only seems to be there so an err can be returned without creating a new one (line 150, net.go). The first item in this list will take care of that, and the error should be made a stringh.genMsg
and h.send
should take a perr, replacing most of their present argumentsRe: items 1 & 4 above, it might be good to leave the err, let it be nil in most cases, and assign to it in the cases where it's needed. Just have to reset it to nil after using it.
Can't make err a shared resource in the perrs. Race condition.
genMsg
has to take 2 more arguments: a string containing whatever additional info might need to be made part of the Msg, and an error.
Once the client is updated, nothing needs to be sent except PERRPERRXXX
This work is done on the Server side. Client updates to come.
Client updated. New tests in.
Instead of explaining them in the doc, and having hardcoded numbers strewn about the place, make the error codes variables in the package.