Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: pr#2339 #214

Merged
merged 1 commit into from
Jul 31, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/Plugins-Guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Fastify 从一开始就搭建成非常模块化的系统. 我们搭建了非常
- [如何处理封装与分发](#distribution)
- [错误处理](#handle-errors)
- [ESM 的支持](#esm-support)
- [自定义错误](#custom-errors)
- [开始!](#start)

<a name="register"></a>
Expand Down Expand Up @@ -319,6 +320,16 @@ fastify
})
```

<a name="custom-errors"></a>
## 自定义错误
假如你的插件需要暴露自定义的错误,[`fastify-error`](https://github.com/fastify/fastify-error) 能帮助你轻松地在代码或插件中生成一致的错误对象。

```js
const createError = require('fastify-error')
const CustomError = createError('ERROR_CODE', 'message')
console.log(new CustomError())
```

<a name="start"></a>
## 开始!
太棒了, 现在你已经知道了所有创建插件需要的关于 Fastify 和它的插件系统的知识, 如果你写了插件请告诉我们! 我们会将它加入到 [*生态*](https://github.com/fastify/fastify#ecosystem) 章节中!
Expand Down