Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Standardize route error handling to use createExpressError

オープン
#261 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
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時間
マージ済み PR(30日)
5

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

CenterForDigitalHumanities/rerum_server_nodejs のほかの issue

CenterForDigitalHumanities/rerum_server_nodejs の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。