Skip to content

Commit 2cb46e3

Browse files
authored
Merge pull request #32856 from github/repo-sync
Repo sync
2 parents d35d0e4 + 654c13a commit 2cb46e3

File tree

5 files changed

+34
-10
lines changed

5 files changed

+34
-10
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@
230230
"hast-util-from-parse5": "^8.0.1",
231231
"hast-util-to-string": "^2.0.0",
232232
"hastscript": "^9.0.0",
233-
"helmet": "^7.0.0",
233+
"helmet": "^7.1.0",
234234
"highlight.js": "11.9.0",
235235
"highlightjs-curl": "^1.3.0",
236236
"hot-shots": "^10.0.0",
Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1+
import type { NextFunction, Response } from 'express'
2+
13
import statsd from '#src/observability/lib/statsd.js'
4+
import { ExtendedRequest } from '@/types'
5+
6+
class AbortError extends Error {
7+
statusCode: number
8+
code: string
9+
constructor(message: string, statusCode: number, code: string) {
10+
super(message)
11+
this.statusCode = statusCode
12+
this.code = code
13+
}
14+
}
215

3-
export default function abort(req, res, next) {
16+
export default function abort(req: ExtendedRequest, res: Response, next: NextFunction) {
417
// If the client aborts the connection, send an error
518
req.once('aborted', () => {
619
// ignore aborts from next, usually has to do with webpack-hmr
@@ -21,9 +34,7 @@ export default function abort(req, res, next) {
2134
}
2235
statsd.increment('middleware.abort', 1, incrementTags)
2336

24-
const abortError = new Error('Client closed request')
25-
abortError.statusCode = 499
26-
abortError.code = 'ECONNRESET'
37+
const abortError = new AbortError('Client closed request', 499, 'ECONNRESET')
2738

2839
// Pass the error to the Express error handler
2940
return next(abortError)

src/frame/middleware/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import express from 'express'
55
import type { NextFunction, Request, Response, Express } from 'express'
66

77
import haltOnDroppedConnection from './halt-on-dropped-connection.js'
8-
import abort from './abort.js'
8+
import abort from './abort'
99
import timeout from './timeout.js'
1010
import morgan from 'morgan'
1111
import datadog from '@/observability/middleware/connect-datadog.js'

src/types.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { Request } from 'express'
2+
3+
// Throughout our codebase we "extend" the Request object by attaching
4+
// things to it. For example `req.context = { currentCategory: 'foo' }`.
5+
// This type aims to match all the custom things we do to requests
6+
// througout the codebase.
7+
export type ExtendedRequest = Request & {
8+
pagePath?: string
9+
context?: {
10+
currentCategory?: string
11+
}
12+
// Add more properties here as needed
13+
}

0 commit comments

Comments
 (0)