Skip to content

Cannot read property 'method' of undefined #21

Closed
@RobertHerhold

Description

@RobertHerhold

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions