balderdashy/sails · error

The 2-ary usage of `res.redirect()` is no longer supported i

Error message

The 2-ary usage of `res.redirect()` is no longer supported in Express 4/Sails v1.  Please use `res.status(statusCode).redirect(address)` instead.

What it means

In Express 4 / Sails v1, the legacy 2-argument form `res.redirect(statusCode, address)` was removed. The res.redirect shim throws this error whenever a second argument is passed, to force migration to the chainable `res.status(code).redirect(address)` form.

Source

Thrown at lib/router/res.js:370

      // _already_ be in the midst of a res.serverError() call.

      if (req._sails && req._sails.log && req._sails.log.error) {
        req._sails.log.error('res.render() failed: ', e);
      }
      else {
        console.error('res.render() failed: ', e);
      }

      if (process.env.NODE_ENV === 'production') { return res.status(e.statusCode||500).send(e.message); }
      else { return res.status(e.statusCode||500).send(); }
    }

  };

  // res.redirect()
  res.redirect = res.redirect || function _redirectShim (address, noLongerSupported) {
    if (!_.isUndefined(noLongerSupported)) {
      throw new Error('The 2-ary usage of `res.redirect()` is no longer supported in Express 4/Sails v1.  Please use `res.status(statusCode).redirect(address)` instead.');
    }

    // For familiarity, set content-type header:
    res.set('content-type', 'text/html');

    // Set location header
    res.set('Location', address);

    return res.status(res.statusCode||302).send('Redirecting to '+encodeURI(address));
  };



  /**
   * res.set( headerName, value )
   *
   * @param {[type]} headerName [description]
   * @param {[type]} value   [description]

View on GitHub (pinned to 7b76422cc2)

Solutions

  1. Change `res.redirect(statusCode, address)` to `res.status(statusCode).redirect(address)`.
  2. If no explicit status is intended, drop the extra argument and call `res.redirect(address)`.
  3. Search the codebase for /res\.redirect\(\s*\d/ to find all legacy 2-ary usages.

Example fix

// before
res.redirect(301, '/new-location');
// after
res.status(301).redirect('/new-location');
Defensive patterns

Strategy: validation

Validate before calling

function redirect(res, code, address) { if (address === undefined) { return res.redirect(code); } if (typeof code !== 'number') { throw new TypeError('status code must be a number'); } return res.status(code).redirect(address); }

Prevention

When it happens

Trigger: Calling `res.redirect(301, '/new-url')` or any call with two arguments to res.redirect() under Sails v1 / Express 4.

Common situations: Upgrading a Sails 0.12 app to v1 and keeping old redirect calls; porting Express 3 code that used res.redirect(status, url).

Related errors


AI-assisted analysis of balderdashy/sails@7b76422cc2 (2026-09-01). Data as JSON: /api/errors/17bd40d315e7221c. Report an issue: GitHub.