refactor: dedupe oauth tls record helper

This commit is contained in:
Peter Steinberger
2026-04-06 23:27:48 +01:00
parent 4aa31ee6e1
commit 0fdb176465
2 changed files with 7 additions and 6 deletions

View File

@@ -1,6 +1,7 @@
import path from "node:path";
import { formatCliCommand } from "../cli/command-format.js";
import type { OpenClawConfig } from "../config/config.js";
import { asNullableObjectRecord } from "../shared/record-coerce.js";
import { note } from "../terminal/note.js";
const TLS_CERT_ERROR_CODES = new Set([
@@ -33,17 +34,13 @@ export type OpenAIOAuthTlsPreflightResult =
message: string;
};
function asRecord(value: unknown): Record<string, unknown> | null {
return value && typeof value === "object" ? (value as Record<string, unknown>) : null;
}
function extractFailure(error: unknown): {
code?: string;
message: string;
kind: PreflightFailureKind;
} {
const root = asRecord(error);
const rootCause = asRecord(root?.cause);
const root = asNullableObjectRecord(error);
const rootCause = asNullableObjectRecord(root?.cause);
const code = typeof rootCause?.code === "string" ? rootCause.code : undefined;
const message =
typeof rootCause?.message === "string"

View File

@@ -7,3 +7,7 @@ export function asRecord(value: unknown): Record<string, unknown> {
export function asNullableRecord(value: unknown): Record<string, unknown> | null {
return isRecord(value) ? value : null;
}
export function asNullableObjectRecord(value: unknown): Record<string, unknown> | null {
return value && typeof value === "object" ? (value as Record<string, unknown>) : null;
}