Files
app/frontend/src/utils.ts
T
stroblme 6c8a101d24 Rename Installation to Instance
Follows the portal: the noun is "instance" everywhere the app says it —
UI strings, CLI output, error details, docs and comments. The wire keys
(`instance_id`, `instance_token`) and the hub route this calls move with it.

An existing cloud.json is adopted rather than refused: without the key
alias the dataclass fails to parse, which the caller swallows and reads as
"never enrolled" instead of "reconnect".

`instance_key` on a node type becomes `target_key`. It means the outside
thing a node points at, which is a different sense of the word, and keeping
both would put two meanings of "instance" in one codebase.
2026-08-31 10:12:01 +02:00

34 lines
1.0 KiB
TypeScript

import { AxiosError } from "axios"
import type { ApiError } from "./client"
import { ago } from "./components/Health/queries"
import { offlineDetail } from "./lib/connectionStore"
function extractErrorMessage(err: ApiError): string {
// An unreachable instance is not a rejected action: say plainly that
// nothing was delivered, so nobody is left wondering whether it half-landed.
const offline = offlineDetail(err)
if (offline) {
return offline.lastSeen
? `Not delivered — the instance is offline (last seen ${ago(offline.lastSeen)})`
: "Not delivered — the instance is offline"
}
if (err instanceof AxiosError) {
return err.message
}
const errDetail = (err.body as any)?.detail
if (Array.isArray(errDetail) && errDetail.length > 0) {
return errDetail[0].msg
}
return errDetail || "Something went wrong."
}
export const handleError = function (
this: (msg: string) => void,
err: ApiError,
) {
const errorMessage = extractErrorMessage(err)
this(errorMessage)
}