soapbox-pub / nostrify

Bring your projects to life on Nostr. 🌱 This repo is a mirror of the source on GitLab.
https://nostrify.dev/
MIT License
5 stars 2 forks source link

Suggestion: include relay url in error object #4

Open antonioconselheiro opened 5 days ago

antonioconselheiro commented 5 days ago

Gm, I would like to suggest to include an attribute in errors thrown in relay, the relay address info.

export class NetworkError extends Error {
  constructor(
    msg: string,
    public relay: WebSocket['url']
  ) {
    super(msg);
  }
}

So you can throw like this:

if (!ok) {
  throw new NetworkError(reason, this.url);
}

https://github.com/soapbox-pub/nostrify/blob/d8afed2c2bd1fc405495dbb8681b4fd1c40f1829/packages/nostrify/NRelay1.ts#L199

You think is make sense?

alexgleason commented 5 days ago

Yes. i almost did it in the first place, but figured I would wait until somebody actually needed it. Mainly because I want to take care how I name this Error class, and where to put it.

antonioconselheiro commented 5 days ago

Good. Knowing the error origin can help users review relay list, by removing relays with more number of errors.