8
package-lock.json
generated
8
package-lock.json
generated
@@ -44,7 +44,7 @@
|
||||
"hast-util-from-parse5": "^8.0.1",
|
||||
"hast-util-to-string": "^2.0.0",
|
||||
"hastscript": "^9.0.0",
|
||||
"helmet": "^7.0.0",
|
||||
"helmet": "^7.1.0",
|
||||
"highlight.js": "11.9.0",
|
||||
"highlightjs-curl": "^1.3.0",
|
||||
"hot-shots": "^10.0.0",
|
||||
@@ -7899,9 +7899,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/helmet": {
|
||||
"version": "7.0.0",
|
||||
"resolved": "https://registry.npmjs.org/helmet/-/helmet-7.0.0.tgz",
|
||||
"integrity": "sha512-MsIgYmdBh460ZZ8cJC81q4XJknjG567wzEmv46WOBblDb6TUd3z8/GhgmsM9pn8g2B80tAJ4m5/d3Bi1KrSUBQ==",
|
||||
"version": "7.1.0",
|
||||
"resolved": "https://registry.npmjs.org/helmet/-/helmet-7.1.0.tgz",
|
||||
"integrity": "sha512-g+HZqgfbpXdCkme/Cd/mZkV0aV3BZZZSugecH03kl38m/Kmdx8jKjBikpDj2cr+Iynv4KpYEviojNdTJActJAg==",
|
||||
"engines": {
|
||||
"node": ">=16.0.0"
|
||||
}
|
||||
|
||||
@@ -230,7 +230,7 @@
|
||||
"hast-util-from-parse5": "^8.0.1",
|
||||
"hast-util-to-string": "^2.0.0",
|
||||
"hastscript": "^9.0.0",
|
||||
"helmet": "^7.0.0",
|
||||
"helmet": "^7.1.0",
|
||||
"highlight.js": "11.9.0",
|
||||
"highlightjs-curl": "^1.3.0",
|
||||
"hot-shots": "^10.0.0",
|
||||
|
||||
@@ -1,6 +1,19 @@
|
||||
import statsd from '#src/observability/lib/statsd.js'
|
||||
import type { NextFunction, Response } from 'express'
|
||||
|
||||
export default function abort(req, res, next) {
|
||||
import statsd from '#src/observability/lib/statsd.js'
|
||||
import { ExtendedRequest } from '@/types'
|
||||
|
||||
class AbortError extends Error {
|
||||
statusCode: number
|
||||
code: string
|
||||
constructor(message: string, statusCode: number, code: string) {
|
||||
super(message)
|
||||
this.statusCode = statusCode
|
||||
this.code = code
|
||||
}
|
||||
}
|
||||
|
||||
export default function abort(req: ExtendedRequest, res: Response, next: NextFunction) {
|
||||
// If the client aborts the connection, send an error
|
||||
req.once('aborted', () => {
|
||||
// ignore aborts from next, usually has to do with webpack-hmr
|
||||
@@ -21,9 +34,7 @@ export default function abort(req, res, next) {
|
||||
}
|
||||
statsd.increment('middleware.abort', 1, incrementTags)
|
||||
|
||||
const abortError = new Error('Client closed request')
|
||||
abortError.statusCode = 499
|
||||
abortError.code = 'ECONNRESET'
|
||||
const abortError = new AbortError('Client closed request', 499, 'ECONNRESET')
|
||||
|
||||
// Pass the error to the Express error handler
|
||||
return next(abortError)
|
||||
@@ -5,7 +5,7 @@ import express from 'express'
|
||||
import type { NextFunction, Request, Response, Express } from 'express'
|
||||
|
||||
import haltOnDroppedConnection from './halt-on-dropped-connection.js'
|
||||
import abort from './abort.js'
|
||||
import abort from './abort'
|
||||
import timeout from './timeout.js'
|
||||
import morgan from 'morgan'
|
||||
import datadog from '@/observability/middleware/connect-datadog.js'
|
||||
|
||||
13
src/types.ts
Normal file
13
src/types.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import type { Request } from 'express'
|
||||
|
||||
// Throughout our codebase we "extend" the Request object by attaching
|
||||
// things to it. For example `req.context = { currentCategory: 'foo' }`.
|
||||
// This type aims to match all the custom things we do to requests
|
||||
// througout the codebase.
|
||||
export type ExtendedRequest = Request & {
|
||||
pagePath?: string
|
||||
context?: {
|
||||
currentCategory?: string
|
||||
}
|
||||
// Add more properties here as needed
|
||||
}
|
||||
Reference in New Issue
Block a user