Files
app/frontend/src/utils.ts
T
stroblmeandClaude Opus 5.5 79ad2a08ea no-em-dash pre-commit hook for user-facing strings, existing em-dashes rewritten
frontend/scripts/no-em-dash.ts walks src/ with the TypeScript parser and flags
an em-dash in JSX text, string literals and template text. A bare "—"
placeholder passes, separators go in no-em-dash.allow.json. The script is
identical to index's copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WgBfkm4rCmtd1T4vHWjEPx
2026-10-15 22:03:36 +02:00

34 lines
1002 B
TypeScript

import { AxiosError } from "axios"
import type { ApiError } from "./client"
import { offlineDetail } from "./lib/connectionStore"
import { ago } from "./lib/utils"
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)
}