Coder Social home page Coder Social logo

fastify-xray's People

Contributors

jeromemacias avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

fastify-xray's Issues

TypeError when using with [email protected]

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
        }
      })
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.