Nexmo / nexmo-cli

Nexmo CLI (Command Line Interface)
https://nexmo.com
MIT License
78 stars 52 forks source link

Using `nexmo number:buy` with an account in trial mode shows `undefined` output #104

Closed leggetter closed 7 years ago

leggetter commented 7 years ago

Steps to reproduce

  1. Sign up for a new account
  2. Set up the CLI to use the account API Key and API Secret
  3. Try to buy a number
  4. See undefined output

    Expected behavior

An appropriate error should be shown explaining why the command failed.

cbetta commented 7 years ago

FYI this is what happens:

info: Request: { host: 'rest.nexmo.com',
  port: 443,
  path: '/number/buy?country=GB&msisdn=447520618997&api_key=6159f78b&api_secret=784a14a6ac71a278',
  method: 'POST',
  headers: 
   { 'Content-Type': 'application/x-www-form-urlencoded',
     Accept: 'application/json',
     'User-Agent': 'nexmo-node/1.1.0-beta1/v6.7.0' } } 
Body: undefined
info: response ended: 401
Validator.response() - Error: 
{ 'error-code': '401',
  'error-code-label': 'authentication failed' }
Validator.response() - Response: 
{ 'error-code': '401',
  'error-code-label': 'authentication failed' }
End Validator.response()
undefined

I need to see why that error message is not bubbling up

cbetta commented 7 years ago

We figured out that the reason for this happening is that the Node library has some inconsistencies in when it returns the error in the error callback vs the response callback. In this case we are receiving an error with an error-code-label instead of a message.

I've opened ticket nexmo/nexmo-node#78 to see if we can improve this.

Additionally the API not giving us anything to work with either. The authentication here was successful but the user was not authorized to buy numbers yet (see trial mode account). I suggest we improve the API to return a 403 (Forbidden) instead of a 401 (Unauthorized) and possibly provide some better messaging with the response to provide some idea as to why this action was forbidden.

@tjlytle did any of this end up in the API spec yet?