Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Standardize route error handling to use createExpressError

未关闭
#261 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
68/100
Issue 类型
重构
描述清晰度
基本清楚
活跃度
冷清
技术栈
javascript
领域
backend

调研方向

从 rest.js 开始检查现有的 utils.createExpressError 模式,然后在路由文件中搜索那些在调用 next(res) 之前为 res 赋值 statusMessage 或 statusCode 的 POST 处理程序。将每个匹配的错误路径替换为标准错误对象模式,并确认所有此类处理程序现在都将创建的错误传递给 next()。

由索引模型根据 Issue 内容生成。

描述

enhancement

Description

The POST handlers in the route files use an unconventional pattern of passing the res object directly to next() as the error argument:

res.statusMessage = 'Improper request method for updating, please use PATCH to add new keys to this object.'
res.status(405)
next(res)

This works because rest.messenger reads err.statusMessage and err.statusCode from whatever object is passed, and the res object happens to have those properties. However, it creates a confusing situation where err === res inside the error handler.

The rest of the codebase uses next(utils.createExpressError({...})) for error handling (see rest.js), which is the standard Express convention.

Standardize these routes to use the same createExpressError pattern as the rest of the codebase:

if (!rest.checkPatchOverrideSupport(req, res)) {
    return next(utils.createExpressError({
        statusCode: 405,
        statusMessage: 'Improper request method for updating, please use PATCH to add new keys to this object.'
    }))
}
controller.patchSet(req, res, next)

Context

Found during static review of #206. Out of scope for that PR since it's a pre-existing pattern.

主要语言
JavaScript
星标
3
派生
6
平均合并
4 天 9 小时
30 天内合并 PR
5

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

CenterForDigitalHumanities/rerum_server_nodejs 的其他 Issue

查看 CenterForDigitalHumanities/rerum_server_nodejs 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。