Archived
org adapter:改正 explainJoseError 注释里的继承关系描述(评审 Important)
「JWTExpired 是 JWTClaimValidationFailed 的子类」是错的 —— jose 5.10.0 里两者都 直接继承 JOSEError,implements 只是 TS 结构化类型声明,运行时不建立继承。 判在前的真实理由是让「已过期」这条更具体的话先命中,不是靠父子关系兜底 —— 错误的继承说法会给日后「简化掉」判断顺序的人一个不存在的依据。仅改注释, 两条 instanceof 分支的顺序与内容一字未动,10/10 测试原样通过。
This commit is contained in:
@@ -46,7 +46,12 @@ function toVerifiedClaims(claims: z.infer<typeof claimsSchema>): VerifiedClaims
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/** jose 的错误 → 人话(手册 4.4)。JWTExpired 是 JWTClaimValidationFailed 的子类,先判它 */
|
/**
|
||||||
|
* jose 的错误 → 人话(手册 4.4)。
|
||||||
|
* 两者都直接继承自 `JOSEError`:类型声明上 `JWTExpired implements JWTClaimValidationFailed`,
|
||||||
|
* 但运行时**没有**继承关系(`implements` 只是结构化类型)。这里判在前不是因为父子,
|
||||||
|
* 而是要让「已过期」这条更具体的话先命中 —— 顺序是给人看的,不是给 instanceof 兜底的。
|
||||||
|
*/
|
||||||
export function explainJoseError(error: unknown, ctx: { readonly issuer: string; readonly audience: string }): string {
|
export function explainJoseError(error: unknown, ctx: { readonly issuer: string; readonly audience: string }): string {
|
||||||
if (error instanceof joseErrors.JWTExpired) return 'token 已过期,用 refresh_token 换个新的';
|
if (error instanceof joseErrors.JWTExpired) return 'token 已过期,用 refresh_token 换个新的';
|
||||||
if (error instanceof joseErrors.JWTClaimValidationFailed) {
|
if (error instanceof joseErrors.JWTClaimValidationFailed) {
|
||||||
|
|||||||
Reference in New Issue
Block a user