Skip to content

Commit

Permalink
Specifically emit expired event for resumption failures
Browse files Browse the repository at this point in the history
  • Loading branch information
estrattonbailey committed Jan 2, 2024
1 parent 2860951 commit 37bb367
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .changeset/loud-apes-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@atproto/api': patch
---

Add additional `AtpSessionEvent` event, `unknown`, and implements it within
`resumeSession`. This is used for unknown exceptions, such as network
connectivity issues.
14 changes: 8 additions & 6 deletions packages/api/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,18 @@ 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) {
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
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 37bb367

Please sign in to comment.