@pixelmeet/errors
v0.8.5
Published
Shared error classes for PixelMeet services
Downloads
232
Readme
@pixelmeet/errors
Shared error classes for PixelMeet backend services.
Installation
pnpm add @pixelmeet/errorsUsage
import { NotFoundError, ValidationError, AppError } from '@pixelmeet/errors'
// Throw a not found error
throw new NotFoundError('User not found')
// Throw a validation error with issues
throw new ValidationError('Invalid input', [
{ path: 'email', message: 'Invalid email format', code: 'invalid_string' }
])
// Custom error with status code
throw new AppError('Something went wrong', 500, 'INTERNAL_ERROR')Available Errors
| Error Class | Status Code | Error Code |
|-------------|-------------|------------|
| AppError | configurable | configurable |
| BadRequestError | 400 | BAD_REQUEST |
| ValidationError | 400 | VALIDATION_ERROR |
| UnauthorizedError | 401 | UNAUTHORIZED |
| NotFoundError | 404 | NOT_FOUND |
| ConflictError | 409 | CONFLICT |
| ResourceAlreadyExistsError | 409 | CONFLICT |
| PresignedUrlGenerationError | 500 | PRESIGNED_URL_ERROR |
Zod Integration
ValidationError automatically extracts issues from Zod errors:
import { ValidationError } from '@pixelmeet/errors'
import { z } from 'zod'
try {
schema.parse(data)
} catch (error) {
throw new ValidationError('Validation failed', undefined, error)
// error.issues will be populated from the ZodError
}Peer Dependencies
zod^3.0.0 || ^4.0.0
