Function: getErrorMessage()
getErrorMessage(
error:unknown,fallback:string):string
Defined in: shared/utils/errorUtils.ts:28
Derives a user-friendly message from an unknown error value.
Parametersโ
errorโ
unknown
Arbitrary value captured from a thrown exception or callback.
fallbackโ
string = "Unknown error"
Message used when the value is not an ://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error.
Returnsโ
string
A string suitable for logging or surfacing to the user.
Remarksโ
When the supplied value is an ://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error instance the underlying message
property is returned. All other values yield the provided fallback string,
allowing a consistent logging surface.
Exampleโ
import { logger } from "@app/services/logger";
try {
await riskyOperation();
} catch (error) {
logger.error("Operation failed", getErrorMessage(error));
}
Default Valueโ
"Unknown error";