Standardize route error handling to use createExpressError
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 68/100
- Issue 类型
- 重构
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- javascript
- 领域
- backend
调研方向
从 rest.js 开始检查现有的 utils.createExpressError 模式,然后在路由文件中搜索那些在调用 next(res) 之前为 res 赋值 statusMessage 或 statusCode 的 POST 处理程序。将每个匹配的错误路径替换为标准错误对象模式,并确认所有此类处理程序现在都将创建的错误传递给 next()。
由索引模型根据 Issue 内容生成。
描述
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
环境准备
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
CenterForDigitalHumanities/rerum_server_nodejs 的其他 Issue
-
bug documentation
难度 2/5 1-3 小时 新手友好度 88/100
-
backend dependencies easy
难度 2/5 1-3 小时 新手友好度 84/100
-
难度 2/5 1-3 小时 新手友好度 82/100
CenterForDigitalHumanities/rerum_server_nodejs#290 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 50/100
-
难度 3/5 1-2 天 新手友好度 74/100
查看 CenterForDigitalHumanities/rerum_server_nodejs 的全部 Issue
相似的 Issue
-
check:passed logos:add
难度 1/5 1 小时以内 新手友好度 82/100
维护者通常 1 天内回复
-
component/administration domain/framework needs-triage Platform(Default) priority/low
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 90/100
semantic-release/gitlab#1032 ·
-
agent/guide documentation hive/hosted-available-lke648397-260827-5n31
难度 1/5 1 小时以内 新手友好度 92/100
维护者通常 1 天内回复
-
agentic-workflows
难度 1/5 1 小时以内 新手友好度 85/100
githubnext/gh-aw-workshop#3933 ·
维护者通常 1 天内回复