Skip to content
This repository has been archived by the owner on Nov 4, 2023. It is now read-only.

TypeError when using with [email protected] #1

Closed
armorkram opened this issue Dec 4, 2020 · 0 comments · Fixed by #2
Closed

TypeError when using with [email protected] #1

armorkram opened this issue Dec 4, 2020 · 0 comments · Fixed by #2

Comments

@armorkram
Copy link

Library versions where error is encountered

Error

~/node_modules/aws-xray-sdk-core/lib/utils.js:19
  var stat = status.toString();
                      ^
TypeError: Cannot read property 'toString' of undefined
  at Object.getCauseTypeFromHttpStatus (~/node_modules/aws-xray-sdk-core/lib/utils.js:19:23)
  at Object.fastifyXrayOnResponse (~/node_modules/fastify-xray/plugin.js:84:33)
  at onResponseIterator (~/node_modules/fastify/lib/reply.js:502:10)
  at next (~/node_modules/fastify/lib/hooks.js:70:20)
  at hookRunner (~/node_modules/fastify/lib/hooks.js:84:3)
  at ServerResponse.onResFinished (~/node_modules/fastify/lib/reply.js:485:7)
  at ServerResponse.emit (events.js:203:15)
  at ServerResponse.EventEmitter.emit (domain.js:448:20)
  at ServerResponse.emitted (~/node_modules/emitter-listener/listener.js:134:21)
  at onFinish (_http_outgoing.js:671:10)
  at process._tickCallback (internal/process/next_tick.js:61:11)

From initial investigation, this is because [email protected] does not yet have the getter for statusCode. This results in fastify-xray/plugin.js:84:33 to pass undefined to getCauseTypeFromHttpStatus

node_modules/fastify-xray/plugin.js

const cause = AWSXRay.utils.getCauseTypeFromHttpStatus(reply.statusCode) // reply doesn't have a statusCode getter/property as of [email protected]

node_modules/aws-xray-sdk-core/lib/utils.js

  getCauseTypeFromHttpStatus: function getCauseTypeFromHttpStatus(status) {
    var stat = status.toString();
    if (stat.match(/^[4][0-9]{2}$/) !== null)
      return 'error';
    else if (stat.match(/^[5][0-9]{2}$/) !== null)
      return 'fault';
  }

Quick workaround that I did is to inject a getter for this:

    if (!Reply.prototype.statusCode) {
      Object.defineProperty(Reply.prototype, 'statusCode', {
        get: function() {
          return this.res.statusCode
        }
      })
    }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant