lib/middleware.js
function () {

  function onLoginResponse(res) {
    if (res.statusCode === 302 && res.headers['location'].indexOf('login.do') === -1) {
      console.log('login success');
    } else {
      throw new Error('Login error');
    }
  }

  request
    .post(process.env.ONEAPM_LOGIN_URL)
    .form({
      encode: true,
      username: process.env.ONEAPM_USERNAME,
      strong: true,
      password: base64(process.env.ONEAPM_PASSWORD),
    })
    .on('response', onLoginResponse);
}
function () {

  function onLoginResponse(res) {
    if (res.statusCode === 302 && res.headers['location'].indexOf('login.do') === -1) {
      console.log('login success');
    } else {
      throw new Error('Login error');
    }
  }

  request
    .post(process.env.ONEAPM_LOGIN_URL)
    .form({
      encode: true,
      username: process.env.ONEAPM_USERNAME,
      strong: true,
      password: base64(process.env.ONEAPM_PASSWORD),
    })
    .on('response', onLoginResponse);
}
function ( ) { function onLoginResponse ( res ) { if ( res . statusCode === 302 && res . headers [ 'location' ] . indexOf ( 'login.do' ) === - 1 ) { console . log ( 'login success' ) ; } else { throw new Error ( 'Login error' ) ; } } request . post ( process . env . ONEAPM_LOGIN_URL ) . form ( { encode : true , username : process . env . ONEAPM_USERNAME , strong : true , password : base64 ( process . env . ONEAPM_PASSWORD ) , } ) . on ( 'response' , onLoginResponse ) ; }
login

@throw Error in case of wrong credetials
login