Skip to content

Commit c6d9d3c

Browse files
authored
chore: reduce uncaught errors in prod (#1229)
1 parent 55bf50e commit c6d9d3c

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

server/utils/atproto/oauth.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ async function getOAuthSession(
6767
})
6868

6969
const currentSession = serverSession.data
70-
if (!currentSession) return { oauthSession: undefined, serverSession }
70+
// TODO (jg): why can a session be `{}`?
71+
if (!currentSession || !currentSession.public?.did) {
72+
return { oauthSession: undefined, serverSession }
73+
}
7174

7275
const oauthSession = await client.restore(currentSession.public.did)
7376
return { oauthSession, serverSession }

server/utils/docs/client.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import { doc, type DocNode } from '@deno/doc'
1111
import type { DenoDocNode, DenoDocResult } from '#shared/types/deno-doc'
12+
import { isBuiltin } from 'node:module'
1213

1314
// =============================================================================
1415
// Configuration
@@ -81,12 +82,9 @@ function createLoader(): (
8182
_cacheSetting?: string,
8283
_checksum?: string,
8384
) => {
84-
let url: URL
85-
try {
86-
url = new URL(specifier)
87-
} catch (e) {
88-
// eslint-disable-next-line no-console
89-
console.error(e)
85+
const url = URL.parse(specifier)
86+
87+
if (url === null) {
9088
return undefined
9189
}
9290

@@ -139,7 +137,11 @@ function createResolver(): (specifier: string, referrer: string) => string {
139137
}
140138

141139
// Handle bare specifiers - resolve through esm.sh
142-
if (!specifier.startsWith('http://') && !specifier.startsWith('https://')) {
140+
if (
141+
!specifier.startsWith('http://') &&
142+
!specifier.startsWith('https://') &&
143+
!isBuiltin(specifier)
144+
) {
143145
// Try to resolve bare specifier relative to esm.sh base
144146
const baseUrl = new URL(referrer)
145147
if (baseUrl.hostname === 'esm.sh') {

shared/types/userSession.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import type { NodeSavedSession, NodeSavedState } from '@atproto/oauth-client-node'
22

33
export interface UserServerSession {
4-
public: {
5-
did: string
6-
handle: string
7-
pds: string
8-
avatar?: string
9-
}
4+
public?:
5+
| {
6+
did: string
7+
handle: string
8+
pds: string
9+
avatar?: string
10+
}
11+
| undefined
1012
// Only to be used in the atproto session and state stores
1113
// Will need to change to Record<string, T> and add a current logged in user if we ever want to support
1214
// multiple did logins per server session
13-
oauthSession: NodeSavedSession | undefined
14-
oauthState: NodeSavedState | undefined
15+
oauthSession?: NodeSavedSession | undefined
16+
oauthState?: NodeSavedState | undefined
1517
}

0 commit comments

Comments
 (0)