mockttp icon indicating copy to clipboard operation
mockttp copied to clipboard

Draft implementation of server.on(handle-error, ...)

Open OnkelTem opened this issue 3 years ago • 7 comments

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.

OnkelTem avatar May 11 '22 14:05 OnkelTem

CLA assistant check
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.

CLAassistant avatar May 11 '22 14:05 CLAassistant

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:

pimterry avatar May 11 '22 14:05 pimterry

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.

OnkelTem avatar May 11 '22 15:05 OnkelTem

What do you think about renaming handle-error to server-error?

OnkelTem avatar May 11 '22 15:05 OnkelTem

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.

pimterry avatar May 12 '22 13:05 pimterry

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.

pimterry avatar May 12 '22 13:05 pimterry

Updated PR, not finished yet: tests to come.

OnkelTem avatar May 12 '22 21:05 OnkelTem