Closed adambutler closed 7 years ago
This is an error in the Node library. Closing and I'll re-open it there.
Actually I am wrong. This is an issue here. We're not catching the error thrown somehow.
Ok seems the problem is with the Node library after all: rather than it returning an error object in this instance it's just returning a string with the HTML response.
@adambutler this has now been fixed. Working to deploy this soon.
nexmo app:create 'File Test 1' 'http://c.betta.
io/answer' 'http://c.betta.io/event'
The API response could not be parsed.
Or:
nexmo app:create 'File Test 1' 'http://c.betta.io/answer' 'http://c.betta.io/event' --debug
info: Request: { host: 'api.nexmo.com',
port: 443,
path: '/v1/applications?name=File%20Test%201&type=voice&answer_url=http://c.betta.io/answer&event_url=http://c.betta.io/event&api_key=1234&api_secret=1234',
method: 'POST',
headers:
{ 'Content-Type': 'application/x-www-form-urlencoded',
Accept: 'application/json',
'User-Agent': 'nexmo-node/1.1.1 node/6.7.0 nexmo-cli/0.3.1' } }
Body: undefined
info: response ended: 504
error: SyntaxError: Unexpected token < in JSON at position 0
at Object.parse (native)
at IncomingMessage.<anonymous> (/Users/cbetta/.nvm/versions/node/v6.7.0/lib/node_modules/nexmo-cli/node_modules/nexmo/lib/HttpClient.js:90:48)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
error: could not convert API response to JSON, above error is ignored and raw API response is returned to client
error: Raw Error message from API
error: <html>
<head><title>504 Gateway Time-out</title></head>
<body bgcolor="white">
<center><h1>504 Gateway Time-out</h1></center>
<hr><center>nginx</center>
</body>
</html>
Validator.response() - Error:
{ message: 'The API response could not be parsed.',
parseError:
SyntaxError: Unexpected token < in JSON at position 0
at Object.parse (native)
at IncomingMessage.<anonymous> (/Users/cbetta/.nvm/versions/node/v6.7.0/lib/node_modules/nexmo-cli/node_modules/nexmo/lib/HttpClient.js:90:48)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9) }
Validator.response() - Response:
null
End Validator.response()
The API response could not be parsed.
I've also added a specific error for errors with codes >= 500
> nexmo app:create 'File Test 1' 'http://c.betta.io/answer' 'http://c.betta.io/event'
Server Error: 504
When the Nexmo API responds with a non
2xx
status code an appropriate response should be printed.Perhaps something like: