0

I have a test that gets an ETIMEDOUT error. I want to know which URL is giving the timeout. I have the following hook already

function logIfError(requestParams, response, context, ee, next) {
  if (response.statusCode !== 200 && response.statusCode !== 204) {
      console.error("%i %s", response.statusCode, response.url);
      if (response.statusCode >= 500) {
          console.log(response.headers['X-Trace-Id'])
      }
      if (response.statusCode >= 400) {
          console.log(response.rawBody.toString())
      }
  }
  next();
}

I added to my scenario

scenarios:
  - name: My Scenario
    afterResponse: logIfError

But I can't see any messages when it times out. There's a note in https://github.com/artilleryio/artillery/issues/437#issuecomment-371801777 that indicates an onError but it is not documented anywhere.

I tried to add it in like this

scenarios:
  - name: My Scenario
    afterResponse: logIfError
    onError: myOnErrorHandler

With my implementation as

function myOnErrorHandler(err, requestParams, context, events, callback) {
  console.log("ERR", err);
  return callback();
}

But again no output

Archimedes Trajano
  • 35,625
  • 19
  • 175
  • 265

1 Answers1

2

I add the following processor

function trapError(requestParams, context, ee, next) {
  if (!requestParams.hooks) {
    requestParams.hooks = {};
  }
  if (!requestParams.hooks.beforeError) {
    requestParams.hooks.beforeError = [];
  }
  requestParams.hooks.beforeError.push((error) => {
    if (error.name !== "HTTPError") {
      console.error(requestParams.url, error.name);
    }
    return error;
  });
  next();
}

And register it as follows

scenarios:
  - name: My Scenario
    beforeRequest: trapError

What this does is exploits the fact that it is using got which provides a beforeError hook

Archimedes Trajano
  • 35,625
  • 19
  • 175
  • 265