Details for 401?
Hey,
I'm in the middle of integrating Authy into our system. One thing that irritates me is how I am supposed to distinguish the various error types that hide under a 401.
Currently it could be
- wrong API keys
- wrong token (for verification)
- wrong user
So how am I supposed to know in the code what the root cause was. We wouldn't want to show the user a message straight from your API (e.g. "User doesn't exist."), but show a customized one.
Currently I do this:
if (errMsg.contains("api key"))
throw new ServiceException("wrong API key");
else if (errMsg.contains("token"))
throw new TokenException();
else if (errMsg.contains("user"))
throw new UserException("user not found");
else
throw new ServiceException(errMsg);
... and this can't be the best way, can it?
Hi Stephan,
Thats sort of true. But really I wouldn't worry about API Key's or user not found error. On production you should just assume you're sending the right key's and when you call authy with and authy_id that the users exists.
If you are using the wrong keys, nothing will work, and you'll find out right away - you can't just deploy without seeing this issue.
You have a point there. Case closed :)