
Company News
/Security News
Socket Selected for OpenAI's Cybersecurity Grant Program
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.
@zenweb/result
Advanced tools
控制器返回结果统一处理,默认返回格式为 JSON
| 配置项 | 类型 | 默认值 | 功能 |
|---|---|---|---|
| failCode | number | 无 | 默认失败代码 |
| failStatus | number | 422 | 默认失败HTTP状态码 |
| json.success | (ctx: Context, data?: unknown): unknown | return { data } | 成功结果包装 |
| json.fail | (ctx: Context, err: ResultFail): unknown | return { err.code, err.data, err.message } | 错误结果包装 |
| exposeUnexpected | boolean | false | 暴露意外错误信息。可以设置环境变量 EXPOSE_UNEXPECTED==1 开启 |
| unexpectedStatus | number | 500 | 意外错误HTTP状态码 |
| unexpectedCode | number | 500 | 意外错误代码 |
无
| 挂载项 | 类型 | 功能 |
|---|---|---|
| success | (data?: unknown): Promise | 成功,输出结果。(注意:代码会继续执行),如果需要等待结果包装需要 await |
| 方法 | 类型 | 功能 |
|---|---|---|
| fail | (message: string): never | 直接输出错误消息 |
| fail | (code: number, message?: string): never | 错误代码 + 错误消息 |
| fail | (detail: ResultFailDetail): never | 失败,输出错误信息并终止代码执行(更多选项) |
import { mapping, fail } from 'zenweb';
export class ResultController {
@mapping()
hello() {
return 'Hello';
}
@mapping()
error() {
fail('error info'); // 在调用 fail 方法后会直接跳出方法并输出
console.log('这行不会执行');
}
}
fail(400); // 错误代码
fail('错误消息');
fail(400, '错误消息'); // 错误代码 + 消息
// 完全自定义
fail({
code: 123,
message: "自定义",
status: 200,
});
FAQs
Zenweb Result module
We found that @zenweb/result demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.