Skip to content

Commit 3104958

Browse files
committed
chore: wrap loadJWKs with try-catch block
1 parent b5ec1b5 commit 3104958

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

server/routes/.well-known/jwks.json.get.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { loadJWKs } from '#server/utils/atproto/oauth'
33
export default defineEventHandler(async _ => {
44
const keys = await loadJWKs()
55
if (!keys) {
6-
console.error('Failed to load JWKs. May not be set')
76
return []
87
}
98

server/utils/atproto/oauth.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,25 @@ export async function loadJWKs(): Promise<Keyset | undefined> {
8989
// If we ever need to add multiple JWKs to rotate keys we will need to add a new one
9090
// under a new variable and update here
9191
const jwkOne = useRuntimeConfig().oauthJwkOne
92-
if (!jwkOne) return undefined
92+
if (!jwkOne) {
93+
if (import.meta.test) {
94+
// eslint-disable-next-line no-console
95+
console.error('Failed to load JWKs (not set).')
96+
}
97+
return undefined
98+
}
9399

94100
// For multiple keys if we need to rotate
95101
// const keys = await Promise.all([JoseKey.fromImportable(jwkOne)])
96102

97-
const keys = await JoseKey.fromImportable(jwkOne)
98-
return new Keyset([keys])
103+
try {
104+
const keys = await JoseKey.fromImportable(jwkOne)
105+
return new Keyset([keys])
106+
} catch (e) {
107+
// eslint-disable-next-line no-console
108+
console.error('Failed to load JWKs.', e)
109+
return undefined
110+
}
99111
}
100112

101113
async function getOAuthSession(event: H3Event): Promise<{

0 commit comments

Comments
 (0)