mockttp
mockttp copied to clipboard
Draft implementation of server.on(handle-error, ...)
It's a follow-up of this ticket: https://github.com/httptoolkit/mockttp/issues/78
Now it should be possible to hide errors for example:
// Hide other errors
server.on('handle-error', () => {});
Still needs works.
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.
Oh, can you add tests for this please? I think you can base them on any of the other subscription types in here: https://github.com/httptoolkit/mockttp/tree/main/test/integration/subscriptions. You can probably use your ENOTFOUND dns error as a good test case to reproduce this I think :smile:
Sure I'll try.
But I have a question. I started to used the ErrorLike type in mockttp-server.ts, but now typedoc is barking:
Warning: ErrorLike, defined at src/util/error.ts:2, is referenced by MockttpServer.on.on.callback.__type.__type.error but not included in the documentation.
I'm not sure where should I add a description. I added it to src/util.ts but it didn't make it happy.
What do you think about renaming handle-error to server-error?
It's not all server errors though - it's only errors during the request handling. There's all sorts of other server errors we can hit in other places, like low-level socket handling or during server startup. I've looked at adding an event for all this before, although I think I remember it being a bit more difficult than it sounds...
Anyway, how about request-handler-error? That makes it very explicit, and that would also differentiate it from websocket-handler-error which we'll probably want in future (with different params) for consistency there.
But I have a question. I started to used the ErrorLike type in mockttp-server.ts, but now typedoc is barking
This means you need to export the ErrorLike type from the package root, so that people can use it themselves, like import { ErrorLike } from 'mockttp'.
It's being a bit overly strict really, but it is still useful because it makes sure that all the types you might need are definitely directly accessible outside the package.
To fix that you just need to add an export type { ErrorLike } from './util/error' in main.ts.
Updated PR, not finished yet: tests to come.