Utility functions that extract stable human-readable error messages from unknown or arbitrary error values.
// Source: https://github.com/moeru-ai/airi | License: MIT | Copyright 2024-PRESENT Neko Ayaka
// Provided via justclaw.it.com; keep this notice with the code.
import { errorMessageFrom } from '@moeru/std'
/**
* Returns a stable human-readable message for an unknown error.
*
* Use when:
* - Surfacing arbitrary thrown values (network failures, third-party errors,
* non-Error throws) to the UI as a string.
*
* Expects:
* - `error` may be anything — Error, string, plain object, undefined.
*
* Returns:
* - The first non-empty message extracted by {@link errorMessageFrom},
* else `unknownMessage`, else the literal `'Unknown error'`.
*/
export function errorMessageFromUnknown(error: unknown, unknownMessage?: string): string {
return errorMessageFrom(error) ?? unknownMessage ?
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key