mirror of
https://github.com/cypress-io/cypress.git
synced 2026-01-30 11:00:35 -06:00
53 lines
1.0 KiB
TypeScript
53 lines
1.0 KiB
TypeScript
import debugModule from 'debug'
|
|
import { Readable } from 'stream'
|
|
import { Request } from '@cypress/request'
|
|
import { HttpMiddleware } from './'
|
|
|
|
const debug = debugModule('cypress:proxy:http:error-middleware')
|
|
|
|
export type ErrorMiddleware = HttpMiddleware<{
|
|
error: Error
|
|
incomingResStream?: Readable
|
|
outgoingReq?: Request
|
|
}>
|
|
|
|
const LogError: ErrorMiddleware = function () {
|
|
debug('error proxying request %o', {
|
|
error: this.error,
|
|
url: this.req.url,
|
|
headers: this.req.headers,
|
|
})
|
|
|
|
this.next()
|
|
}
|
|
|
|
export const AbortRequest: ErrorMiddleware = function () {
|
|
if (this.outgoingReq) {
|
|
debug('aborting outgoingReq')
|
|
this.outgoingReq.abort()
|
|
}
|
|
|
|
this.next()
|
|
}
|
|
|
|
export const UnpipeResponse: ErrorMiddleware = function () {
|
|
if (this.incomingResStream) {
|
|
debug('unpiping resStream from response')
|
|
this.incomingResStream.unpipe()
|
|
}
|
|
|
|
this.next()
|
|
}
|
|
|
|
export const DestroyResponse: ErrorMiddleware = function () {
|
|
this.res.destroy()
|
|
this.end()
|
|
}
|
|
|
|
export default {
|
|
LogError,
|
|
AbortRequest,
|
|
UnpipeResponse,
|
|
DestroyResponse,
|
|
}
|