@ciphercross/nestjs-errors
v1.0.0
Published
Standardized error handling for NestJS applications
Readme
@ciphercross/nestjs-errors
Standardized error handling for NestJS applications. Automatically converts all exceptions to a consistent ErrorResponse format that integrates seamlessly with @ciphercross/nestjs-contracts.
Installation
npm install @ciphercross/nestjs-errorsTesting
Running Tests
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:covTest Structure
Tests are located alongside source files with .spec.ts extension:
src/domain/domain-error.spec.ts- DomainError class testssrc/domain/error.factory.spec.ts- Error factory testssrc/utils/sanitize-error.util.spec.ts- Sanitization utility testssrc/utils/type-guards.util.spec.ts- Type guard testssrc/mappers/*.spec.ts- Mapper testssrc/filters/all-exceptions.filter.spec.ts- Exception filter tests
Coverage
The project aims for 80% code coverage. Run coverage report:
npm run test:covCoverage report will be generated in coverage/ directory.
Test Configuration
Jest configuration is in jest.config.js:
- Uses
ts-jestpreset for TypeScript support - Mocks
@ciphercross/nestjs-contractsto avoid peer dependency issues - Excludes type files and interfaces from coverage
- Sets up test environment in
src/__tests__/setup.ts
Development
Quality Checks
# Run all quality checks (lint, format, type-check)
npm run quality
# Lint code
npm run lint
# Fix linting issues
npm run lint:fix
# Format code
npm run format
# Check formatting
npm run format:check
# Type check without building
npm run type-checkBuilding
# Build the library
npm run build
# Clean build artifacts
npm run cleanPublishing
Automatic Publishing via GitHub Actions
The library is automatically published to npm when a version tag is pushed.
Method 1: Using Version Bump Workflow (Recommended)
- Go to GitHub Actions → "Bump Version" workflow
- Click "Run workflow"
- Select version type (patch/minor/major)
- Review and merge the created PR
- Create a tag
v<new-version>(e.g.,v1.0.1) to trigger publish
Method 2: Manual Tag Creation
- Update version in
package.jsonmanually - Commit and push changes
- Create and push a tag:
git tag v1.0.0 git push origin v1.0.0 - The publish workflow will automatically:
- Extract version from tag
- Run tests and linting
- Build the package
- Publish to npm
- Create GitHub release
Method 3: Manual Workflow Dispatch
- Go to GitHub Actions → "Publish to NPM" workflow
- Click "Run workflow"
- Enter version number (e.g.,
1.0.0) - Workflow will publish to npm
Setup Required
Before publishing, configure the following GitHub secrets:
- NPM_TOKEN - npm access token with publish permissions
- Create at: https://www.npmjs.com/settings/YOUR_USERNAME/tokens
- Required permissions:
AutomationorPublish
Workflows
- CI - Runs on every push/PR: tests, linting, type checking
- Publish to NPM - Publishes package when tag is created
- Bump Version - Automatically creates PR with version bump
Usage
See the main documentation for usage examples and API reference.
