mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
feat: add server restart coordination and health status tracking (#300)
* feat: add server restart coordination and health status tracking * refactor: consolidate server restart logic, extract hooks, remove dead code
This commit is contained in:
1 parent
68cd6b5a0b
commit
217f5bd989
19 files changed
+802
-259
No files matched your search
@@ -137,3 +137,49 @@ export function getErrorMessage(error: OpenCodeError | undefined | null): string
|
||||
const parsed = parseOpenCodeError(error)
|
||||
return parsed ? `${parsed.title}: ${parsed.message}` : ''
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts a human-readable message from a Manager REST API error, handling
|
||||
* both {@link FetchError} and axios-style `{ response: { data } }` shapes,
|
||||
* including OpenCode config validation issues and removed fields.
|
||||
*/
|
||||
export function getOpenCodeApiErrorMessage(error: unknown, fallback: string): string {
|
||||
if (error instanceof FetchError) {
|
||||
let message = error.detail || error.message || fallback
|
||||
|
||||
if (error.validationIssues && error.validationIssues.length > 0) {
|
||||
const issues = error.validationIssues
|
||||
.map((issue) => `${issue.path}: ${issue.message}`)
|
||||
.join('; ')
|
||||
message = `Validation failed: ${issues}`
|
||||
}
|
||||
|
||||
if (error.removedFields && error.removedFields.length > 0) {
|
||||
message += ` (removed invalid fields: ${error.removedFields.join(', ')})`
|
||||
}
|
||||
|
||||
return message
|
||||
}
|
||||
|
||||
if (error && typeof error === 'object' && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { details?: string; error?: string; validationIssues?: Array<{ path: string; message: string }>; removedFields?: string[] } } }).response
|
||||
const data = response?.data
|
||||
|
||||
let message = data?.details || data?.error || fallback
|
||||
|
||||
if (data?.validationIssues && data.validationIssues.length > 0) {
|
||||
const issues = data.validationIssues
|
||||
.map((issue) => `${issue.path}: ${issue.message}`)
|
||||
.join('; ')
|
||||
message = `Validation failed: ${issues}`
|
||||
}
|
||||
|
||||
if (data?.removedFields && data.removedFields.length > 0) {
|
||||
message += ` (removed invalid fields: ${data.removedFields.join(', ')})`
|
||||
}
|
||||
|
||||
return message
|
||||
}
|
||||
|
||||
return fallback
|
||||
}
|
||||
Reference in new issue
Block a user