{"record":{"id":"17bd40d315e7221c","repo":"balderdashy/sails","slug":"the-2-ary-usage-of-res-redirect-is-no-longer-s","errorCode":null,"errorMessage":"The 2-ary usage of `res.redirect()` is no longer supported in Express 4/Sails v1.  Please use `res.status(statusCode).redirect(address)` instead.","messagePattern":"The 2-ary usage of `res\\.redirect\\(\\)` is no longer supported in Express 4/Sails v1\\.  Please use `res\\.status\\(statusCode\\)\\.redirect\\(address\\)` instead\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/router/res.js","lineNumber":370,"sourceCode":"      // _already_ be in the midst of a res.serverError() call.\n\n      if (req._sails && req._sails.log && req._sails.log.error) {\n        req._sails.log.error('res.render() failed: ', e);\n      }\n      else {\n        console.error('res.render() failed: ', e);\n      }\n\n      if (process.env.NODE_ENV === 'production') { return res.status(e.statusCode||500).send(e.message); }\n      else { return res.status(e.statusCode||500).send(); }\n    }\n\n  };\n\n  // res.redirect()\n  res.redirect = res.redirect || function _redirectShim (address, noLongerSupported) {\n    if (!_.isUndefined(noLongerSupported)) {\n      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.');\n    }\n\n    // For familiarity, set content-type header:\n    res.set('content-type', 'text/html');\n\n    // Set location header\n    res.set('Location', address);\n\n    return res.status(res.statusCode||302).send('Redirecting to '+encodeURI(address));\n  };\n\n\n\n  /**\n   * res.set( headerName, value )\n   *\n   * @param {[type]} headerName [description]\n   * @param {[type]} value   [description]","sourceCodeStart":352,"sourceCodeEnd":388,"githubUrl":"https://github.com/balderdashy/sails/blob/7b76422cc27823df033572bdda5c4910a68b697f/lib/router/res.js#L352-L388","documentation":"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.","triggerScenarios":"Calling `res.redirect(301, '/new-url')` or any call with two arguments to res.redirect() under Sails v1 / Express 4.","commonSituations":"Upgrading a Sails 0.12 app to v1 and keeping old redirect calls; porting Express 3 code that used res.redirect(status, url).","solutions":["Change `res.redirect(statusCode, address)` to `res.status(statusCode).redirect(address)`.","If no explicit status is intended, drop the extra argument and call `res.redirect(address)`.","Search the codebase for /res\\.redirect\\(\\s*\\d/ to find all legacy 2-ary usages."],"exampleFix":"// before\nres.redirect(301, '/new-location');\n// after\nres.status(301).redirect('/new-location');","handlingStrategy":"validation","validationCode":"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); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never call res.redirect with two positional arguments in Sails v1.","Use a small helper wrapper for status-coded redirects.","Codemod `res.redirect(\\d+,` patterns during 0.12 → v1 upgrades.","Enable lint rules or code review checks for legacy Express 3 signatures."],"tags":["sails","express","redirect","migration","breaking-change"],"backgroundTag":"removed-express-redirect-signature","analyzedSha":"7b76422cc27823df033572bdda5c4910a68b697f","analyzedAt":"2026-09-01T04:01:57.104Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}