@adonisjs/generic-exceptions

中文文档
3.0.1发布于 2018/10/21MITCommonJS近 30 天下载 5.5万

List of generic exceptions to be used in all other repos

原始使用文档
文档目录3 节
  1. Setup
  2. Usage
  3. RuntimeException

AdonisJs Generic Exceptions 🚀

Customized exceptions for AdonisJs

NPM Version

This repo contains some helpful classes to throw uniform exceptions through out the application. Ofcourse you can throw exceptions using new Error() but using this package will help in throwing informative exceptions.

Setup

Install package using npm.

npm i @adonisjs/generic-exceptions

Usage

The package exports all exceptions from node-exceptions and adds additional methods to the RuntimeException class.

const { InvalidArgumentException } = require('@adonisjs/generic-exceptions')

const message = 'Model.create requires an object'
const status = 400
const code = 'E_INVALID_ARGUMENT'

throw new InvalidArgumentException(message, status, code)

The status must be a valid HTTP status code and code is a unique error code to recognize an exception. AdonisJs error codes starts with E_, for example: E_MISSING_CONFIG.

RuntimeException

The following static methods are added to the runtime exception to make the adonisJs related exceptions consistent.

missingConfig(key, file)

missingAppKey(providerName)

incompleteConfig(missingKeys, file)

invoke(message, status, [code])

Checkout the complete API docs here

版本与发布记录

@adonisjs/generic-exceptions 共发布 5 个版本,首次发布于 2017/08/02;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.0.1latest2018/10/218 年前
3.0.02018/10/208 年前
2.0.12018/05/118 年前
2.0.02018/01/168 年前
1.0.02017/08/029 年前

关于 @adonisjs/generic-exceptions 的常见问题

@adonisjs/generic-exceptions 是什么?

List of generic exceptions to be used in all other repos

如何安装 @adonisjs/generic-exceptions?

在项目目录运行 npm install @adonisjs/generic-exceptions,或使用 pnpm add / yarn add / bun add。

@adonisjs/generic-exceptions 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/adonisjs__generic-exceptions 是否存在。

@adonisjs/generic-exceptions 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@adonisjs/generic-exceptions 可以商用吗?

@adonisjs/generic-exceptions 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@adonisjs/generic-exceptions 的下载量有多少?

根据 npm 官方下载统计,@adonisjs/generic-exceptions 在 2026/10/05 – 2026/11/03 这 30 天内被下载 55,269 次,日均约 1,842 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@adonisjs/generic-exceptions 还在维护吗?

最新版本 3.0.1 发布于 2018/10/21(8 年前);至今共发布 5 个版本,其中过去 12 个月发布了 0 个;首次发布于 2017/08/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。