Skip to content

Commit 335739e

Browse files
committed
fix: 🐛 harden error introspection
1 parent 0ce9374 commit 335739e

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/json-crdt-repo/session/EditSessionFactory.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ export class EditSessionFactory {
6161
const {model, cursor} = await (typeof timeoutMs === 'number'
6262
? timeout(timeoutMs, repo.pull(id))
6363
: repo.pull(id));
64-
if (remote.throwIf === 'exists') throw new Error('EXISTS');
65-
const session = new EditSession(repo, id, model, cursor, opts.session);
66-
session.log.end.api.autoFlush();
67-
return session;
68-
} catch (error) {
69-
if (error instanceof Error && error.message === 'TIMEOUT') {
64+
if (remote.throwIf === 'exists') throw new Error('EXISTS');
65+
const session = new EditSession(repo, id, model, cursor, opts.session);
66+
session.log.end.api.autoFlush();
67+
return session;
68+
} catch (error) {
69+
if (!!error && typeof error === 'object' && (error as Record<string, unknown>).message === 'TIMEOUT') {
7070
if (!opts.make) throw error;
71-
} else if (error instanceof Error && error.message === 'NOT_FOUND') {
71+
} else if (!!error && typeof error === 'object' && ((error as Record<string, unknown>).message === 'NOT_FOUND' || (error as Record<string, unknown>).code === 'NOT_FOUND')) {
7272
if (remote.throwIf === 'missing') throw error;
7373
} else throw error;
7474
}

0 commit comments

Comments
 (0)