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

Offen
#554 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 4 Tagen

@Dx-Alz-xD arbeitet bereits daran.

Seit 11.11.2026.

  • #561 von @Dx-Alz-xD — offen

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
35/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Veraltet
Tech-Stack
typescript

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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

Vorherrschende Sprache
TypeScript
Sterne
23
Forks
67
Ø Merge
2 T. 17 Std.
Gemergte PRs (30 T.)
7

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus CodeChefVIT/papers-codechef

Alle Issues in CodeChefVIT/papers-codechef

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.