Closed garygriswold closed 9 years ago
What would you expect to happen instead? Particularly on the client, throwing an Error is the only sensible thing I can see for it to do in the face of a clearly invalid key being provided?
Alex,
If you are not willing to change it, I can always write my own wrapper that returns false in the verification method whether the input is null, invalid, or simply the wrong key. From my experience, I can’t imagine a code review coming to any other recommendation. For a user of an application, which uses this library, a client program crash needs to be avoided because it leaves a non-technical the end user with no idea of the source of the problem. While a response that they are unauthorized will at least help the end user understand who to contact to correct the problem.
If you are willing to give me one more response, I would very much like to know if your opinions on library error handling are entirely your own, or do they also reflect programming policy inside Joyent, or does Joyent have no policy on such matters?
Sincerely yours,
Gary Griswold
On Sep 10, 2015, at 1:58 PM, Alex Wilson notifications@github.com wrote:
What would you expect to happen instead? Particularly on the client, throwing an Error is the only sensible thing I can see for it to do in the face of a clearly invalid key being provided?
— Reply to this email directly or view it on GitHub https://github.com/joyent/node-http-signature/issues/46#issuecomment-139327627.
If you want to know about the general Joyent views on error handling in node.js, please see https://www.joyent.com/developers/node/design/errors -- in this particular case, we have a synchronous API and this is an operational error (the function was given invalid data). The standard way to return this to the consumer of the API is by throwing an Error (see the example of what JSON.parse
does).
Your application can use a try { } catch { }
block to handle this case, it does not need to crash all the way back to the end user.
Working with the sample code, I tried changing a valid signing key and a valid verification key by 1 character. The change in the signing key crashed the client. The change in the verification key crashed the server. The following are the errors.
On client, when signing key was altered.
On server, when validation key was altered.