Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@qnx/errors

yatendra12122MIT0.7.10TypeScript support: included

Collection for handle express error response

errors, error codes

readme

@qnx/errors

@qnx/errors provides a set of custom error classes to help you simplify and standardize error handling in your JavaScript/TypeScript applications.


✨ Features

  • Predefined error classes for common scenarios
  • Consistent structure for error responses
  • Easy integration with APIs and validation logic

📦 Installation

You can install via your preferred package manager:

# npm
npm install @qnx/errors

# yarn
yarn add @qnx/errors

# pnpm
pnpm install @qnx/errors

🚀 Usage

Importing Errors

import {
  ApiError,
  ValidationError,
  InvalidValueError,
  UnauthenticatedUserError,
  ServerError
} from '@qnx/errors'

📘 Error Class Examples

ApiError

const apiError = new ApiError('Something went wrong', 500, {
  errRes: {
    message: 'Server failed to respond',
    errors: {
      generic: ['Unexpected error occurred']
    }
  }
})

console.log(apiError.message) // "Something went wrong"
console.log(apiError.getCode()) // 500
console.log(apiError.getErrorResponse()) // { message: "...", errors: ... }

ValidationError

const validationError = new ValidationError('Validation failed', {
  errRes: {
    message: 'Validation errors found',
    errors: {
      email: ['Email is invalid'],
      password: ['Password must be at least 8 characters']
    }
  }
})

console.log(validationError.getCode()) // errorCodes.VALIDATION_ERROR_CODE
console.log(validationError.getErrorResponse()) // Detailed error response

InvalidValueError

const error = new InvalidValueError('Username cannot contain spaces', {
  key: 'username'
})

console.log(error.getCode()) // errorCodes.VALIDATION_ERROR_CODE
console.log(error.getErrorResponse()) // { errors: { username: ['Username cannot contain spaces'] } }

UnauthenticatedUserError

const authError = new UnauthenticatedUserError('User not authenticated')

console.log(authError.getCode()) // errorCodes.UNAUTHENTICATED_USER_ERROR_CODE
console.log(authError.message) // "User not authenticated"

ServerError

const serverError = new ServerError('Internal server error')

console.log(serverError.getCode()) // errorCodes.SERVER_ERROR_CODE
console.log(serverError.message) // "Internal server error"

📊 Summary Table

Error Class Purpose Default Code Use When...
ApiError Generic base error Custom You need a customizable error
ValidationError Multi-field form validation 422 Input or schema validation fails
InvalidValueError Single field validation 422 One field like "email" or "username` is bad
UnauthenticatedUserError Auth failure 401 User not logged in or token missing
ServerError Internal system failure 500 Something broke that user can’t fix

🤝 Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.

📄 License

MIT License © 2023-PRESENT Yatendra Kushwaha

changelog

0.7.10 (2025-07-11)

🩹 Fixes

  • chore: release 0.7.10 ()

0.7.9 (2025-06-15)

🩹 Fixes

  • chore: release v0.6.9 ()

0.7.8 (2025-06-07)

🩹 Fixes

  • chore: release 0.7.8 ()

0.7.7 (2025-04-24)

🩹 Fixes

  • release v0.7.7 ()

0.7.6 (2025-04-24)

🩹 Fixes

  • release v0.7.6 ()

0.7.5 (2025-04-01)

🩹 Fixes

  • chore: release 0.7.5 ()

1.0.0 (2025-02-06)

🚀 Features

  • ⚠️ release v0.7.1 ()

⚠️ Breaking Changes

  • ⚠️ release v0.7.1 ()

0.6.28 (2025-01-07)

🩹 Fixes

  • chore: release 0.6.28 ()

0.6.27 (2024-12-02)

🩹 Fixes

  • feat(workspace): update deps ()

0.6.6 (2024-10-15)

🩹 Fixes

  • fix version conflict ()

0.6.5 (2024-10-11)

🩹 Fixes

  • chore: v0.6.25 ()

0.6.4 (2024-10-11)

🩹 Fixes

  • chore: v0.6.24 ()

0.6.3 (2024-09-29)

🩹 Fixes

  • release v0.6.24 ()

0.6.2 (2024-09-29)

🩹 Fixes

  • chore: release 0.6.22 ()

0.6.22 (2024-09-29)

🩹 Fixes

  • (fix): update dependencies ()

0.6.1 (2024-09-17)

🩹 Fixes

  • (fix): update dependencies ()

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

0.0.7 (2023-12-20)

Features

0.0.6 (2023-12-20)

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.