-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft implementation of server.on(handle-error, ...) #79
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ import { | |
} from "./types"; | ||
import type { RequestRuleData } from "./rules/requests/request-rule"; | ||
import type { WebSocketRuleData } from "./rules/websockets/websocket-rule"; | ||
import { ErrorLike } from "./util/error"; | ||
|
||
export type PortRange = { startPort: number, endPort: number }; | ||
|
||
|
@@ -415,6 +416,23 @@ export interface Mockttp { | |
*/ | ||
on(event: 'client-error', callback: (error: ClientError) => void): Promise<void>; | ||
|
||
/** | ||
* Subscribe to hear about requests that fail before successfully sending their | ||
* initial parameters (the request line & headers). This will fire for requests | ||
* that drop connections early, send invalid or too-long headers, or aren't | ||
* correctly parseable in some form. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment needs updating |
||
* | ||
* This is only useful in some niche use cases, such as logging all requests | ||
* seen by the server, independently of the rules defined. | ||
* | ||
* The callback will be called asynchronously from request handling. This function | ||
* returns a promise, and the callback is not guaranteed to be registered until | ||
* the promise is resolved. | ||
* | ||
* @category Events | ||
*/ | ||
on(event: 'handle-error', callback: (error: ErrorLike) => void): Promise<void>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think it would be useful to include the request that failed here too as a second parameter, something like That would be as an |
||
|
||
/** | ||
* Adds the given rules to the server. | ||
* | ||
|
@@ -576,7 +594,8 @@ export type SubscribableEvent = | |
| 'response' | ||
| 'abort' | ||
| 'tls-client-error' | ||
| 'client-error'; | ||
| 'client-error' | ||
| 'handle-error'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be |
||
|
||
/** | ||
* @hidden | ||
|
@@ -677,4 +696,4 @@ export abstract class AbstractMockttp { | |
return new WebSocketRuleBuilder(this.addWebSocketRule); | ||
} | ||
|
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make this work, you'll need to:
Error
type withmessage
andstack
string fields.{ message, stack }
data into a properError
object.I think that should be it, and then the identical API will work in browser & remote clients automatically too.