koboldcpp/tools/ui/src/lib/constants/error.ts
Marcos Del Sol Vives 69cea5b669
ui: simplify network error handling (#23431)
Previously error to string conversion was split in two different files,
with one converting errors into strings, and another function analyzing
those strings to generate yet another string.

Now the the error handling for network fetches has been centralised and
uses directly HTTP error codes whereas possible to generate the
human-readable error strings.

It also fixes an issue where all JSON errors reported from the backend,
such as "Invalid API key", would get turned incorrectly in to
"Failed to connect to server" due to poor matching logic in the
now-gone getErrorMessage function.
2026-06-02 10:45:25 +02:00

23 lines
745 B
TypeScript

export const ERROR_MESSAGES = {
NETWORK: {
GENERIC: 'Failed to connect to server',
NXDOMAIN: 'Server not found - check server address',
REFUSED: 'Connection refused - server may be offline',
TIMEOUT: 'Request timed out',
UNREACHABLE: 'Server is not running or unreachable'
},
HTTP: {
GENERIC: 'Request failed',
ACCESS_DENIED: 'Access denied',
INTERNAL_ERROR: 'Server error - check server logs',
NOT_FOUND: 'Not found',
TEMPORARILY_UNAVAILABLE: 'Server temporarily unavailable'
}
};
export const HTTP_CODE_TO_STRING: Record<string, string> = {
401: ERROR_MESSAGES.HTTP.ACCESS_DENIED,
403: ERROR_MESSAGES.HTTP.ACCESS_DENIED,
500: ERROR_MESSAGES.HTTP.INTERNAL_ERROR,
503: ERROR_MESSAGES.HTTP.TEMPORARILY_UNAVAILABLE
};