ErrorHub is a centralized error management system with message localization. The system allows developers to use error codes instead of text messages in code, while dynamically retrieving user-facing messages by code and required locale through API.
- 🌐 Multilingual out of the box - support for message localization in different languages
- 🔄 Dynamic message retrieval - real-time error text retrieval via API
- 💻 SDK for various platforms - Node.js, browser, and Fastify plugin support
- 🧰 Administrative interface - for managing messages and translations
- 📦 Caching - multi-level caching for fast access to messages
- 🔌 Integrations - with loggers, monitoring, and CI/CD
The project is built as a monorepo using npm workspaces and includes the following packages:
packages/sdk- SDK for working with the error APIpackages/api- REST API serverpackages/admin-ui- administrative interfacepackages/shared-ui- shared UI components
SDK for integration with the error API, including:
- Core module with basic functionality
- Browser module for use in the browser
- Node module with Fastify plugin support
- Message caching for performance optimization
- Parameter substitution in message templates
REST API server based on Fastify for:
- Retrieving error messages by code and locale
- Batch loading of messages
- Creating, updating, and deleting errors
- Managing localizations
Web interface for:
- Managing the error catalog
- Creating and editing messages
- Translating messages into different languages
- Importing/exporting translations
git clone https://github.com/yourusername/errorHub.git
cd errorHubnpm installnpm run buildimport { ErrorHub } from '@errorhub/sdk';
const errorHub = new ErrorHub({
apiUrl: 'https://api.errorhub.example.com',
apiKey: 'your-api-key',
defaultLanguage: 'en'
});
// Getting an error message
const error = await errorHub.getError('USER.NOT_FOUND', 'ru');
console.log(error.message); // "Пользователь не найден"
// Using with parameters
const message = await errorHub.getMessage(
'ORDER.ITEM.OUT_OF_STOCK',
'en',
{ item: 'Laptop' }
);
console.log(message); // "Item 'Laptop' is out of stock"import Fastify from 'fastify';
import { ErrorHub } from '@errorhub/sdk';
const fastify = Fastify();
const errorHub = new ErrorHub({
apiUrl: 'https://api.errorhub.example.com',
apiKey: 'your-api-key',
defaultLanguage: 'en'
});
// Plugin registration
fastify.register(errorHub.createFastifyPlugin());
// Using in a route
fastify.get('/users/:id', async (request, reply) => {
// Getting an error
if (!userExists) {
return reply.sendErrorResponse('USER.NOT_FOUND', 404);
}
// Regular response
return { user };
});
fastify.listen({ port: 3000 });import { ErrorHub } from '@errorhub/sdk';
const errorHub = new ErrorHub({
apiUrl: 'https://api.errorhub.example.com',
apiKey: 'your-api-key',
defaultLanguage: 'en',
cache: {
enabled: true,
ttl: 3600000 // 1 hour
}
});
// Handling form error
async function validateForm() {
if (!isPasswordStrong(password)) {
const message = await errorHub.getMessage('VALIDATION.PASSWORD_TOO_WEAK');
showError(message);
}
}cd packages/api
npm run devThe server will be available at http://localhost:4000
cd packages/admin-ui
npm run devThe interface will be available at http://localhost:3000
ErrorHub is built on the following principles:
- Separation of concerns - service layer contains business logic and data access
- API-first - all interactions happen through API
- Multi-level caching - for optimal performance
- Extensibility - possibility to add new error types and integrations
+-------------+ +--------------+ +---------------+
| Application |----->| ErrorHub SDK |----->| ErrorHub API |
| (client) |<-----| (caching) |<-----| (server) |
+-------------+ +--------------+ +------^--------+
|
+------+--------+
| Database |
| (errors and |
| translations)|
+---------------+
errorHub/
├── packages/
│ ├── sdk/
│ │ ├── core/
│ │ │ ├── types.ts
│ │ │ └── index.ts
│ │ ├── browser/
│ │ │ └── index.ts
│ │ ├── node/
│ │ │ └── index.ts
│ │ └── index.ts
│ ├── api/
│ │ └── src/
│ │ ├── middleware/
│ │ │ └── error-handler.ts
│ │ ├── routes/
│ │ │ ├── index.ts
│ │ │ └── error-routes.ts
│ │ ├── services/
│ │ │ ├── ErrorService.ts
│ │ │ ├── CategoryService.ts
│ │ │ └── TranslationService.ts
│ │ └── index.ts
│ ├── admin-ui/
│ └── shared-ui/
└── package.json
npm run devThis will start all packages in development mode with change tracking.
MIT