[READ-ONLY] a fast, modern browser for the npm registry

chore: reduce uncaught errors in prod (#1229)

authored by

James Garbutt and committed by
GitHub
c6d9d3ce 55bf50ec

+23 -16
+4 -1
server/utils/atproto/oauth.ts
··· 67 67 }) 68 68 69 69 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 + } 71 74 72 75 const oauthSession = await client.restore(currentSession.public.did) 73 76 return { oauthSession, serverSession }
+9 -7
server/utils/docs/client.ts
··· 9 9 10 10 import { doc, type DocNode } from '@deno/doc' 11 11 import type { DenoDocNode, DenoDocResult } from '#shared/types/deno-doc' 12 + import { isBuiltin } from 'node:module' 12 13 13 14 // ============================================================================= 14 15 // Configuration ··· 81 82 _cacheSetting?: string, 82 83 _checksum?: string, 83 84 ) => { 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) { 90 88 return undefined 91 89 } 92 90 ··· 139 137 } 140 138 141 139 // 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 + ) { 143 145 // Try to resolve bare specifier relative to esm.sh base 144 146 const baseUrl = new URL(referrer) 145 147 if (baseUrl.hostname === 'esm.sh') {
+10 -8
shared/types/userSession.ts
··· 1 1 import type { NodeSavedSession, NodeSavedState } from '@atproto/oauth-client-node' 2 2 3 3 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 10 12 // Only to be used in the atproto session and state stores 11 13 // Will need to change to Record<string, T> and add a current logged in user if we ever want to support 12 14 // multiple did logins per server session 13 - oauthSession: NodeSavedSession | undefined 14 - oauthState: NodeSavedState | undefined 15 + oauthSession?: NodeSavedSession | undefined 16 + oauthState?: NodeSavedState | undefined 15 17 }