CustomPolicy: switch to NoOpPolicy if the policy isn't found

This commit is contained in:
Alex Gleason 2024-05-31 13:51:10 -05:00
parent 9d50a76c0c
commit 5ca1e2fd26
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 10 additions and 3 deletions

View File

@ -1,6 +1,6 @@
import 'deno-safe-fetch/load';
import { NostrEvent, NostrRelayOK, NPolicy } from '@nostrify/nostrify';
import { ReadOnlyPolicy } from '@nostrify/nostrify/policies';
import { NoOpPolicy, ReadOnlyPolicy } from '@nostrify/nostrify/policies';
import * as Comlink from 'comlink';
export class CustomPolicy implements NPolicy {
@ -12,8 +12,15 @@ export class CustomPolicy implements NPolicy {
}
async import(path: string): Promise<void> {
try {
const Policy = (await import(path)).default;
this.policy = new Policy();
} catch (e) {
if (e.message.includes('Module not found')) {
this.policy = new NoOpPolicy();
}
throw e;
}
}
}