@haatlabs-core/errors
v0.10.0
Published
AppError, shared error codes and typed per-app codes with defineErrors.
Readme
@haatlabs-core/errors
AppError, the codes every project shares, and defineErrors for a project's own. Shared
code recognises any project's error (instanceof AppError); each project's codes stay typed.
import { defineErrors } from '@haatlabs-core/errors';
import type { z } from 'zod';
export const { ErrorCode, ERROR_DEFINITIONS, AppError, ErrorEnvelopeSchema } = defineErrors({
SEARCH_PROVIDER_ERROR: { httpStatus: 503, transient: true },
});
export type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];
export type AppError = InstanceType<typeof AppError>;
export type ErrorEnvelope = z.infer<typeof ErrorEnvelopeSchema>;instanceof AppError holds for an AppError made by any copy of this package (pnpm can install
two, for two versions of a peer), and a project's AppError recognises a platform error
whose code it has. isAppError, isTransientError and safeErrorMessage are here too. zod
is a peer dependency.
Install
pnpm add @haatlabs-core/errorsIt leaves one package to your app, so the app holds one copy: zod.
