@myko.pk/errors
v1.0.2
Published
Shared error types for MYKOPK packages
Readme
📑 Table of Contents
- Description
- Key Features
- Use Cases
- Tech Stack
- Quick Start
- Available Scripts
- Project Structure
- Contributors
- Contributing
- License
📝 Description
@myko.pk/errors provides structured error classes and typed error codes for the MYKO ecosystem. Every MYKO package — from database adapters to HTTP services — throws errors from this library, ensuring consistent error shape, serialization, and HTTP status code mapping across the entire stack. Includes DatabaseError and RedisError classes with structured context, typed error code enums, and automatic status code inference.
✨ Key Features
- 🧱 Structured Error Classes —
DatabaseErrorandRedisErrorwithcode,statusCode,cause, andcontextfields. - 🔢 Typed Error Codes —
DATABASE_ERROR_CODESandREDIS_ERROR_CODESenums for type-safe error handling. - 🌐 HTTP Status Mapping — Every error code maps to an appropriate HTTP status code automatically.
- 📦 JSON Serializable —
toJSON()for clean API responses. - 📘 Fully Typed — Full TypeScript support with exported code type utilities.
🎯 Use Cases
- Throwing consistent
DatabaseErrorinstances from every database adapter (Drizzle, Prisma, SQL, Supabase) with a shared error code vocabulary. - Mapping internal error codes to HTTP status codes for REST API responses.
- Structured error logging with
causeandcontextfor debugging distributed systems.
🛠️ Tech Stack
- 📘 TypeScript
Notable libraries: None — pure error classes, zero runtime deps.
⚡ Quick Start
npm install @myko.pk/errorsimport { DatabaseError, DATABASE_ERROR_CODES } from '@myko.pk/errors';
import { REDIS_ERROR_CODES } from '@myko.pk/errors/codes';
throw new DatabaseError(DATABASE_ERROR_CODES.CONNECT_FAILED, {
cause: originalError,
context: { host: 'db-primary' },
});
// JSON serialization: { code: 'db.connect_failed', statusCode: 503, ... }🚀 Available Scripts
- build —
npm run build - typecheck —
npm run typecheck
📁 Project Structure
.
├── CHANGELOG.md
├── CONTRIBUTING.md
├── LICENSE
├── SECURITY.md
├── package.json
├── src
│ ├── codes
│ │ └── index.ts
│ ├── errors
│ │ ├── DatabaseError.ts
│ │ ├── RedisError.ts
│ │ └── index.ts
│ └── index.ts
├── tsconfig.json
└── tsup.config.mjs🛠️ Development Setup
- Install Node.js (v18+ recommended)
- Install dependencies:
npm install - Build:
npm run build
🧪 Testing
This project currently exports error classes — runtime tests can be added via Vitest.
npm run test👥 Contributors
See the full list of contributors →
👥 Contributing
Contributions are welcome! Here's the standard flow:
- Fork the repository
- Clone your fork:
git clone https://github.com/mykopk/errors.git - Branch:
git checkout -b feature/your-feature - Commit:
git commit -m 'feat: add some feature' - Push:
git push origin feature/your-feature - Open a pull request
Please follow the existing code style and include tests for new behavior where applicable.
📜 License
This project is licensed under the MIT License.
Company
MYKO Pakistan
Detail Information Website myko.pk Email [email protected] About Building digital infrastructure and super-app experiences for millions of users across Pakistan. Built with ❤️ in Pakistan 🇵🇰
