Skip to content

Cannot read property 'method' of undefined #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
RobertHerhold opened this issue Aug 14, 2015 · 3 comments
Closed

Cannot read property 'method' of undefined #21

RobertHerhold opened this issue Aug 14, 2015 · 3 comments
Assignees
Labels

Comments

@RobertHerhold
Copy link
Contributor

Environment: Node.js
Version: 2.0.0

Stack:

[TypeError: Cannot read property 'method' of undefined]
TypeError: Cannot read property 'method' of undefined
    at logResponse (/js-data-http/src/index.js:136:56)
    at lib$es6$promise$$internal$$tryCatch (/js-data-http/node_modules/es6-promise/dist/es6-promise.js:331:16)
    at lib$es6$promise$$internal$$invokeCallback (/js-data-http/node_modules/es6-promise/dist/es6-promise.js:343:17)
    at lib$es6$promise$$internal$$publish (/js-data-http/node_modules/es6-promise/dist/es6-promise.js:314:11)
    at lib$es6$promise$$internal$$publishRejection (/js-data-http/node_modules/es6-promise/dist/es6-promise.js:264:7)
    at lib$es6$promise$asap$$flush (/js-data-http/node_modules/es6-promise/dist/es6-promise.js:125:9)
    at doNTCallback0 (node.js:407:9)
    at process._tickCallback (node.js:336:13)

Problem: When running js-data-http in Node.js it attempts to open a connection to whatever endpoint you have specified. If the server is not up, it creates an ECONNREFUSED Error. By default, js-data-http tries to log both error and success promise callbacks with the same function, logResponse, which assumes an object structure that is not an Error object.

ECONNREFUSED Error object:

{ [Error: connect ECONNREFUSED 127.0.0.1:80]
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 80 }

Line in logResponse() assumes a data.config.method... object structure to exist.

let str = `${start.toUTCString()} - ${data.config.method.toUpperCase()} ${data.config.url} - ${data.status} ${(new Date().getTime() - start.getTime())}ms`;

I will work on a PR for this.

@jmdobry
Copy link
Member

jmdobry commented Aug 14, 2015

I will work on a PR for this.

Sweet!

@RobertHerhold
Copy link
Contributor Author

@jmdobry For PRs, do you want the compiled source submitted as well?
From a security perspective you should not let anyone do this, but I want to hear your thoughts.

At any rate, your answer should be recorded in CONTRUBUTING.md.

@jmdobry
Copy link
Member

jmdobry commented Aug 14, 2015

No, I'll commit that just before a release.

@jmdobry jmdobry added the bug label Sep 12, 2015
@jmdobry jmdobry self-assigned this Sep 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants