katanakit-js / useErrorNormalize
Function: useErrorNormalize()
ts
function useErrorNormalize(error, fallbackStatus?): {
details?: unknown;
message: string;
status: number;
};Defined in: src/core/services/error.service.ts:75
Normalizes any thrown value into the shared ApiError shape.
Reads message, numeric status (or statusCode, used by some SDKs) and details when present; every other value becomes a generic error. This is the canonical mapper for useAttempt() at service boundaries.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
error | unknown | undefined | The caught value (Error, SDK error object, string, …). |
fallbackStatus | number | 0 | Status used when the value has none (default: 0). |
Returns
ts
{
details?: unknown;
message: string;
status: number;
}A serializable { message, status, details? } error.
details?
ts
optional details?: unknown;message
ts
message: string;status
ts
status: number;Example
ts
import { useAttempt, useErrorNormalize } from "katanakit-js";
const result = await useAttempt(() => sdk.call(), useErrorNormalize);
if (!result.ok) console.error(result.error.status, result.error.message);