You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

27 lines
802 B

import type { AbstractRelay } from 'nostr-tools/abstract-relay'
const patched = new WeakSet<object>()
/**
* One-time patch: forward every relay NOTICE to the app (strikes / rate-limit cooldown / logs).
* Safe to call on every ensureRelay; only the first patch per relay instance applies.
*/
export function patchRelayNoticeForFetchFailures(
relay: AbstractRelay,
relayKey: string,
onNotice?: (relayKey: string, noticeMessage: string) => void
): void {
if (!onNotice || patched.has(relay as object)) return
patched.add(relay as object)
const previous = relay.onnotice.bind(relay)
relay.onnotice = (msg: string) => {
if (typeof msg === 'string' && msg.trim()) {
try {
onNotice(relayKey, msg)
} catch {
/* ignore */
}
}
previous(msg)
}
}