question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

beforeRequest hook doesn't work

See original GitHub issue

Hi guys! I noticed the next issue: When trying to change my json before sending, defined beforeRequest function is not called. Adding afterResponse function working as expected. My code looks like that:

 {
  "config": {
    "target": "...my target...",
    "phases": [
      {"duration": 10, "arrivalRate": 5}
    ],
    "processor" : "helloJS.js",
    "defaults": {
      "headers": {
        "content-type": "application/json"
      }
    }
  },
  "scenarios": [
    {
      "flow": [
        {
          "post": {
            "url": "...my url...",
            "json": {
                 "my json"
            },
            "beforeRequest" : "foo"
          }
        }
      ]
    }
  ]
}
module.exports = {
    foo: foo
};

function foo (requestParams, context, ee, next) {
    console.log("TEST");
    return next();
}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
danielo515commented, Sep 30, 2016

You’re welcome @hassy

As a suggestion this worked fine for me:

if ( !_.isArray(scenarioSpec.beforeRequest)) {
      scenarioSpec.beforeRequest = scenarioSpec.beforeRequest ? [scenarioSpec.beforeRequest] : [];
    }

Regards

0reactions
hassycommented, Sep 30, 2016

It needs to be set to an empty array if it’s not defined (and left alone if it’s an array). Easy fix. Thanks for investigating @danielo515!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Intercept each request with before and after hooks
I have to make 5 requests (order doesn't matter) to 5 different endpoints. The URL of these endpoints is the same, except for...
Read more >
Hooks - Fastify
The onResponse hook is executed when a response has been sent, so you will not be able to send more data to the...
Read more >
axios-hooks - npm
In the example below we use the useAxios hook twice. Once to load the data when the component renders, and once to submit...
Read more >
Cancel request before actual request #1012 - Issuehunt
Example (this is not working, it might just better illustrate what I want to do): ... @sindresorhus You can already modify options in...
Read more >
Before request hook - Google Groups
I would like to check user credentials in every REST request, before any other hooks are triggered. The idea is to prevent any...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found