CenterForDigitalHumanities / CenterForDigitalHumanities/rerum_server_nodejs

Standardize route error handling to use createExpressError

Offen
#261 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
enhancement
Vorherrschende Sprache
JavaScript
Sterne
3
Forks
6
Ø Merge
2 T. 47 Min.
Gemergte PRs (30 T.)
4

Beschreibung

## Description

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

```javascript
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:

```javascript
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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne mit rest.js, um das bestehende Muster utils.createExpressError zu überprüfen, und durchsuche dann die Routendateien nach POST-Handlern, die statusMessage oder statusCode auf res setzen, bevor sie next(res) aufrufen. Ersetze jeden passenden Fehlerpfad durch das standardmäßige Fehlerobjekt-Muster und bestätige, dass alle diese Handler nun erstellte Fehler an next() übergeben.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript
Bereich
backend
Issue-Typ
Refactoring
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Ruhig
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
68/100

Neue Issues direkt in Ihr Postfach

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