airqo-platform / airqo-platform/AirQo-api

Refactor: Standardize error handling in role-permissions.util.js

Abierto
#4,440 0 comentarios 0 reacciones 1 asignado Reclamado por @Baalmart Ver en GitHub
Lenguaje dominante
JavaScript
Estrellas
26
Forks
24
Merge medio
5 h 36 min
PR fusionados (30 d)
81

Descripción

## Background

Currently, there are inconsistent patterns for error handling in `role-permissions.util.js`. The new `getDefaultGroupRole` function uses `throw new HttpError` while other functions use `next(new HttpError)`.

## Proposed Change

Standardize error handling across all functions to use `throw new HttpError` pattern:

```diff
} catch (error) {
logger.error(`🐛🐛 Internal Server Error ${error.message}`);
- next(
- new HttpError(
- "Internal Server Error",
- httpStatus.INTERNAL_SERVER_ERROR,
- { message: error.message }
- )
- );
+ throw new HttpError(
+ "Internal Server Error",
+ httpStatus.INTERNAL_SERVER_ERROR,
+ { message: error.message }
+ );
}
```

## Benefits
- Consistent error handling pattern throughout the file
- Cleaner error propagation
- Better alignment with JavaScript's error handling mechanisms

## References
- PR: #4439
- Discussion: https://github.com/airqo-platform/AirQo-api/pull/4439#discussion_r1957321666

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.