diff --git a/content/admin/overview/index.md b/content/admin/overview/index.md index 7c88265d86..87c75cdcce 100644 --- a/content/admin/overview/index.md +++ b/content/admin/overview/index.md @@ -13,7 +13,6 @@ children: - /about-enterprise-accounts - /managing-your-github-enterprise-license - /managing-billing-for-your-enterprise - - /about-upgrades-to-new-releases - /system-overview - /about-the-github-enterprise-api --- diff --git a/middleware/catch-bad-accept-language.js b/middleware/catch-bad-accept-language.js new file mode 100644 index 0000000000..8ce70b967c --- /dev/null +++ b/middleware/catch-bad-accept-language.js @@ -0,0 +1,15 @@ +const accept = require('@hapi/accept') + +// Next.JS uses the @hapi/accept package to parse and detect languages. If the accept-language header is malformed +// it throws an error from within Next.JS, which results in a 500 response. This ends up being noisy because we +// track 500s. To counteract this, we'll try to catch the error first and make sure it doesn't happen +module.exports = function catchBadAcceptLanguage (req, res, next) { + try { + accept.language(req.headers['accept-language']) + } catch (e) { + // if there's a problem with parsing 'accept-language', just clear it out. + req.headers['accept-language'] = '' + } + + return next() +} diff --git a/middleware/index.js b/middleware/index.js index 87274e377a..8077d83e80 100644 --- a/middleware/index.js +++ b/middleware/index.js @@ -54,6 +54,7 @@ module.exports = function (app) { app.use(require('compression')()) app.use(require('./disable-caching-on-safari')) app.use(require('./set-fastly-surrogate-key')) + app.use(require('./catch-bad-accept-language')) // *** Config and context for redirects *** app.use(require('./req-utils')) // Must come before record-redirect and events diff --git a/package-lock.json b/package-lock.json index 41b9496059..6c2b12e6a9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,6 +7,7 @@ "name": "docs.github.com", "license": "(MIT AND CC-BY-4.0)", "dependencies": { + "@hapi/accept": "^5.0.2", "@primer/components": "^28.0.4", "@primer/css": "^16.2.0", "@primer/octicons": "^14.1.0", diff --git a/package.json b/package.json index 3d4248d662..ad4e7a4609 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ ".next/cache" ], "dependencies": { + "@hapi/accept": "^5.0.2", "@primer/components": "^28.0.4", "@primer/css": "^16.2.0", "@primer/octicons": "^14.1.0",