/api/paper-by-id returns 500 instead of 404 for a paper that doesn't exist

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

维护者通常 4 天内回复

@Dx-Alz-xD 已经在做这个了。

开始于 2026年11月11日。

  • #561 来自 @Dx-Alz-xD —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
typescript

调研方向

Read src/lib/services/paper.ts at the linked getPaperById code and inspect the /api/paper-by-id route plus @/lib/utils/error for the existing error handling pattern. Verify the behavior for a valid ObjectId with no matching paper; done means the endpoint returns 404 with “Paper not found” and the paper page can distinguish that from a server error. Pull request #561 is already open for this issue.

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

描述

Describe the bug
getPaperById throws a plain Error("Paper not found") (with a // 404 comment) and the route catches every error and returns 500 "Failed to fetch paper"

https://github.com/CodeChefVIT/papers-codechef/blob/6e3aa1152a34c7eb46d36f58294dffd9ff3b3c7b/src/lib/services/paper.ts#L43

To Reproduce

  1. Request /api/paper-by-id/<a valid ObjectId that isn't in the database>, e.g. /api/paper-by-id/000000000000000000000000
  2. The response is 500 "Failed to fetch paper"

Expected behavior
404 "Paper not found". CustomError and customErrorHandler from @/lib/utils/error (added in #436) already do this. Throwing new CustomError("Paper not found", 404) and using customErrorHandler in the route would fix it and the paper page could then tell "not found" apart from a server error

主要语言
TypeScript
星标
23
派生
67
平均合并
2 天 17 小时
30 天内合并 PR
7

环境准备

从这里开始

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

CodeChefVIT/papers-codechef 的其他 Issue

查看 CodeChefVIT/papers-codechef 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

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