Skip to content

TypeError: Cannot read property 'message' of undefined #245

Open

Description

@engrsriram

i just visited this code and started trying in my machine.

mkdir resttest
cd resttest
npm install restler
node

after i am getting into command line interface i typed given sample codes. and i am getting bellow mentioned error.

> var rest = require('restler');
undefined
> rest.get('http://twaud.io/api/v1/users/danwrong.json').on('complete', function(data) {
...   console.log(data[0].message); // auto convert to object
... });
{ domain: null,
  _events: { error: [Function], complete: [Function] },
  _maxListeners: 10,
  url:
   { protocol: 'http:',
     slashes: true,
     auth: null,
     host: 'twaud.io',
     port: '80',
     hostname: 'twaud.io',
     hash: null,
     search: null,
     query: null,
     pathname: '/api/v1/users/danwrong.json',
     path: '/api/v1/users/danwrong.json',
     href: 'http://twaud.io/api/v1/users/danwrong.json' },
  options:
   { method: 'GET',
     parser: { [Function] matchers: [Object] },
     followRedirects: true },
  headers:
   { Accept: '*/*',
     'User-Agent': 'Restler for node.js',
     Host: 'twaud.io',
     'Accept-Encoding': 'gzip, deflate',
     'Content-Length': 0 },
  request:
   { domain: null,
     _events:
      { socket: [Object],
        response: [Function],
        error: [Function] },
     _maxListeners: 10,
     output: [],
     outputEncodings: [],
     writable: true,
     _last: false,
     chunkedEncoding: false,
     shouldKeepAlive: true,
     useChunkedEncodingByDefault: false,
     sendDate: false,
     _headerSent: false,
     _header: '',
     _hasBody: true,
     _trailer: '',
     finished: false,
     _hangupClose: false,
     socket: null,
     connection: null,
     agent:
      { domain: null,
        _events: [Object],
        _maxListeners: 10,
        options: {},
        requests: {},
        sockets: [Object],
        maxSockets: 5,
        createConnection: [Function] },
     socketPath: undefined,
     method: 'GET',
     path: '/api/v1/users/danwrong.json',
     _headers:
      { accept: '*/*',
        'user-agent': 'Restler for node.js',
        host: 'twaud.io',
        'accept-encoding': 'gzip, deflate',
        'content-length': 0 },
     _headerNames:
      { accept: 'Accept',
        'user-agent': 'User-Agent',
        host: 'Host',
        'accept-encoding': 'Accept-Encoding',
        'content-length': 'Content-Length' } } }
>
undefined
>
undefined
>
repl:2
console.log(data[0].message); // auto convert to object
                   ^
TypeError: Cannot read property 'message' of undefined
    at Request.<anonymous> (repl:2:20)
    at Request.emit (events.js:98:17)
    at Request.mixin._fireSuccess (/home/sriram/projects/worker/node_modules/restler/lib/restler.js:229:10)
    at /home/sriram/projects/worker/node_modules/restler/lib/restler.js:161:20
    at IncomingMessage.parsers.auto (/home/sriram/projects/worker/node_modules/restler/lib/restler.js:402:7)
    at Request.mixin._encode (/home/sriram/projects/worker/node_modules/restler/lib/restler.js:198:29)
    at /home/sriram/projects/worker/node_modules/restler/lib/restler.js:157:16
    at Request.mixin._decode (/home/sriram/projects/worker/node_modules/restler/lib/restler.js:173:7)
    at IncomingMessage.<anonymous> (/home/sriram/projects/worker/node_modules/restler/lib/restler.js:150:14)
    at IncomingMessage.emit (events.js:117:20)

as you can notice that this is almost silly thing but i am missing something which i am not sure.

please let us know if there is any logic behind which i am not aware.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions