Import the client, server, skills, tests, and build scripts as the starting point for the rebuild, then trim the surfaces this project does not ship: Electron desktop packaging, the marketing website, and the ESP32 firmware tree. CI keeps the web build, e2e, lockfile, release, and Docker workflows. Rename the package and CLI entry points to hermes-ui, drop the prepare hook so npm ci no longer triggers a build, and drop the removed tsconfig and nodemon references. Rewrite AGENTS.md, ARCHITECTURE.md, DEVELOPMENT.md, and the READMEs so the documented package map and hard rules match this repository. reference_code/ is ignored: it is a read-only snapshot, not an input to the build.
49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
function errorMessageText(error: unknown): string {
|
|
if (typeof error === 'string') return error.trim()
|
|
if (error == null) return ''
|
|
if (typeof error !== 'object') return String(error).trim()
|
|
|
|
if (Array.isArray(error)) {
|
|
return error.map(errorMessageText).filter(Boolean).join('\n')
|
|
}
|
|
|
|
const record = error as Record<string, unknown>
|
|
for (const key of ['message', 'error', 'detail', 'description', 'code']) {
|
|
const text = errorMessageText(record[key])
|
|
if (text) return text
|
|
}
|
|
|
|
try {
|
|
return JSON.stringify(error)
|
|
} catch {
|
|
return String(error)
|
|
}
|
|
}
|
|
|
|
export async function responseErrorMessage(
|
|
response: Response,
|
|
fallbackPrefix = 'Request failed',
|
|
): Promise<string> {
|
|
let detail = ''
|
|
|
|
const contentType = response.headers.get('content-type') || ''
|
|
if (contentType.includes('application/json')) {
|
|
try {
|
|
detail = errorMessageText(await response.clone().json())
|
|
} catch {
|
|
detail = ''
|
|
}
|
|
}
|
|
|
|
if (!detail) {
|
|
try {
|
|
detail = (await response.clone().text()).trim()
|
|
} catch {
|
|
detail = ''
|
|
}
|
|
}
|
|
|
|
const base = `${fallbackPrefix}: ${response.status}`
|
|
return detail ? `${base} - ${detail}` : base
|
|
}
|