From 618610021f78e4ed144760ddc7aff447b88ac882 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Je=CC=81ro=CC=82me=20Macias?= Date: Sun, 6 Dec 2020 22:48:55 +0100 Subject: [PATCH] Fix Fastify < 2.10.0 compatibility --- .travis.yml | 7 +++++++ plugin.js | 6 ++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index c814f45..ddfa4a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,13 @@ node_js: - "lts/*" - "node" +env: + - FASTIFY_VERSION=^2.0.0 + - FASTIFY_VERSION=2.9.0 + +before_script: + - npm i --no-save fastify@$FASTIFY_VERSION + script: - npm run lint-ci - npm run test-ci diff --git a/plugin.js b/plugin.js index a3cfbd1..c375570 100644 --- a/plugin.js +++ b/plugin.js @@ -77,11 +77,13 @@ function plugin (fastify, options, next) { return done() } - if (reply.statusCode === 429) { + const statusCode = reply.statusCode || reply.res.statusCode + + if (statusCode === 429) { segment.addThrottleFlag() } - const cause = AWSXRay.utils.getCauseTypeFromHttpStatus(reply.statusCode) + const cause = AWSXRay.utils.getCauseTypeFromHttpStatus(statusCode) if (cause) { segment[cause] = true }