CenterForDigitalHumanities / CenterForDigitalHumanities/rerum_server_nodejs
Standardize route error handling to use createExpressError
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- JavaScript
- Estrellas
- 3
- Forks
- 6
- Merge medio
- 2 d 47 min
- PR fusionados (30 d)
- 4
Descripción
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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con rest.js para revisar el patrón existente de utils.createExpressError y, después, busca en los archivos de rutas los manejadores POST que asignen statusMessage o statusCode en res antes de llamar a next(res). Reemplaza cada ruta de error coincidente por el patrón estándar de objeto de error y confirma que todos esos manejadores ahora pasan los errores creados a next().
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript
- Área
- backend
- Tipo de issue
- Refactorización
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Tranquilo
- Claridad
- Bastante claro
- Aptitud para principiantes
- 68/100