domain-errors

Standardize SaaS domain errors with typed codes and NestJS HTTP mapping.

Updated Mar 26, 2026
One-click install
npx skills add https://github.com/johnnystefan/test-saas-business --skill domain-errors
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: domain-errors
Source: https://github.com/johnnystefan/test-saas-business/tree/main/skills/domain-errors
Command: npx skills add https://github.com/johnnystefan/test-saas-business --skill domain-errors

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Business domain errors across the SaaS services lack a shared structure and HTTP mapping, making it hard to handle business rule violations, validation issues, and resource failures consistently.

Core Features & Use Cases

  • Base DomainError class provides typed codes, titles, messages, and context so every service defines errors from a single contract rooted in libs/shared/types/src/errors/domain-error.ts.
  • Concrete errors and validation such as ResourceNotFoundError, BusinessRuleViolationError, InvalidArgumentError, and DomainValidationError encapsulate rich context, offer convenient static factories, and integrate Zod safeParse results.
  • NestJS DomainErrorFilter maps the typed codes to HTTP statuses and can be registered globally to ensure consistent client responses across auth, club, inventory, booking, finance, and shared libraries.
  • Use Case: When a booking rule is violated, throw BusinessRuleViolationError so the exception filter returns a 422 response with a consistent code and message.

Quick Start

Define a DomainError subclass for your resource and register the DomainErrorFilter to translate errors into HTTP responses.

Frequently Asked Questions about domain-errors

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I standardize domain error handling across NestJS services?

Standardize domain error handling by defining a base DomainError class with typed codes, then registering a NestJS ExceptionFilter to map those codes to consistent HTTP statuses globally across your services.

How does NestJS map domain errors to HTTP status codes?

NestJS maps domain errors to HTTP statuses using a DomainErrorFilter that catches typed error codes—like resource, business, or validation failures—and translates them into consistent client responses such as 422 for business rule violations.

How do I integrate Zod validation errors into NestJS exception handling?

Integrate Zod validation errors by passing safeParse results into a DomainValidationError class, which encapsulates the validation context and feeds it to the NestJS ExceptionFilter for a structured HTTP response.

Can I use a shared error structure across auth, inventory, and booking services?

Yes, you can define a shared base DomainError class in a common library and use it across auth, club, inventory, booking, and finance services to ensure every domain failure follows a single, consistent contract.

What is the best way to handle business rule violations in a SaaS backend?

Handle business rule violations by throwing a BusinessRuleViolationError with rich context, allowing the registered NestJS ExceptionFilter to catch it and return a 422 HTTP response with a consistent code and message.

Why do my SaaS services return inconsistent HTTP responses for similar errors?

Inconsistent HTTP responses occur when services lack a shared domain error structure, which you resolve by standardizing errors with a base DomainError class and mapping typed codes to statuses via a NestJS ExceptionFilter.