diff --git a/.changeset/loud-apes-listen.md b/.changeset/loud-apes-listen.md new file mode 100644 index 00000000000..6b8ca5389f4 --- /dev/null +++ b/.changeset/loud-apes-listen.md @@ -0,0 +1,5 @@ +--- +'@atproto/api': patch +--- + +Emit `expired` events for failed responses from `agent.resumeSession` instead of `create-failed`. `create-failed` events now reserved for unexpected exceptions, like a network timeout. diff --git a/packages/api/src/agent.ts b/packages/api/src/agent.ts index aea3cce9d4b..399cf0a28f4 100644 --- a/packages/api/src/agent.ts +++ b/packages/api/src/agent.ts @@ -159,6 +159,7 @@ export class AtpAgent { try { this.session = session const res = await this.api.com.atproto.server.getSession() + console.log('resumeSession', res) if (!res.success || res.data.did !== this.session.did) { throw new Error('Invalid session') } @@ -166,16 +167,19 @@ export class AtpAgent { this.session.handle = res.data.handle this.session.emailConfirmed = res.data.emailConfirmed this._updateApiEndpoint(res.data.didDoc) + this._persistSession?.('create', this.session) return res - } catch (e) { + } catch (e: any) { + console.error('resumeSession', e) this.session = undefined - throw e - } finally { - if (this.session) { - this._persistSession?.('create', this.session) - } else { + + if (e.message.includes('Invalid session')) { this._persistSession?.('create-failed', undefined) + } else { + this._persistSession?.('unknown', undefined) } + + throw e } } diff --git a/packages/api/src/types.ts b/packages/api/src/types.ts index c0f78bfaafc..978c5759aff 100644 --- a/packages/api/src/types.ts +++ b/packages/api/src/types.ts @@ -3,7 +3,7 @@ import { LabelPreference } from './moderation/types' /** * Used by the PersistSessionHandler to indicate what change occurred */ -export type AtpSessionEvent = 'create' | 'create-failed' | 'update' | 'expired' +export type AtpSessionEvent = 'create' | 'create-failed' | 'update' | 'expired' | 'unknown' /** * Used by AtpAgent to store active sessions