async-express-error 1.0.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +247 -61
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/package.json +60 -5
- package/index.js +0 -13
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 J2mCoder
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,61 +1,247 @@
|
|
|
1
|
-
# async-express-error
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
app
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
1
|
+
# async-express-error
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/async-express-error)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://github.com/J2mCoder/async-express-error/actions/workflows/ci.yml)
|
|
6
|
+
[](https://codecov.io/gh/J2mCoder/async-express-error)
|
|
7
|
+
|
|
8
|
+
## Description
|
|
9
|
+
|
|
10
|
+
`async-express-error` est une bibliothèque utilitaire pour Express.js qui permet de gérer les erreurs de manière centralisée dans les fonctions asynchrones. Elle enveloppe les fonctions asynchrones pour capturer et transmettre automatiquement les erreurs au middleware `next()` d'Express, simplifiant ainsi la gestion des erreurs dans vos routes.
|
|
11
|
+
|
|
12
|
+
✨ **Nouveau dans la v2.0.0** : Support TypeScript complet avec types génériques !
|
|
13
|
+
|
|
14
|
+
## Fonctionnalités
|
|
15
|
+
|
|
16
|
+
- 🎯 **Gestion automatique des erreurs** - Plus besoin de try/catch dans chaque route
|
|
17
|
+
- 🔷 **TypeScript support complet** - Types génériques pour une inférence de type optimale
|
|
18
|
+
- 🧪 **100% testé** - Suite de tests complète avec Jest
|
|
19
|
+
- 📦 **Léger** - Zéro dépendance runtime
|
|
20
|
+
- ⚡ **Compatible** - Fonctionne avec Express 4 et 5
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install async-express-error
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Utilisation
|
|
29
|
+
|
|
30
|
+
### JavaScript
|
|
31
|
+
|
|
32
|
+
```javascript
|
|
33
|
+
const express = require("express");
|
|
34
|
+
const asyncHandler = require("async-express-error");
|
|
35
|
+
|
|
36
|
+
const app = express();
|
|
37
|
+
|
|
38
|
+
// Exemple d'une route utilisant async-express-error
|
|
39
|
+
app.get(
|
|
40
|
+
"/users/:id",
|
|
41
|
+
asyncHandler(async (req, res, next) => {
|
|
42
|
+
const user = await getUserById(req.params.id);
|
|
43
|
+
res.json(user);
|
|
44
|
+
})
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
// Middleware de gestion des erreurs
|
|
48
|
+
app.use((err, req, res, next) => {
|
|
49
|
+
console.error(err);
|
|
50
|
+
res.status(500).json({ error: err.message });
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
app.listen(3000);
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### TypeScript (Recommandé)
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import express, { Request, Response, NextFunction } from "express";
|
|
60
|
+
import asyncHandler from "async-express-error";
|
|
61
|
+
|
|
62
|
+
const app = express();
|
|
63
|
+
|
|
64
|
+
// Avec types génériques pour une meilleure sécurité de type
|
|
65
|
+
interface UserParams {
|
|
66
|
+
id: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface User {
|
|
70
|
+
id: string;
|
|
71
|
+
name: string;
|
|
72
|
+
email: string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
app.get(
|
|
76
|
+
"/users/:id",
|
|
77
|
+
asyncHandler<UserParams, User>(async (req, res) => {
|
|
78
|
+
// req.params.id est typé comme string
|
|
79
|
+
const user = await getUserById(req.params.id);
|
|
80
|
+
// res.json attend un objet de type User
|
|
81
|
+
res.json(user);
|
|
82
|
+
})
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
// Middleware de gestion des erreurs typé
|
|
86
|
+
app.use((err: Error, req: Request, res: Response, next: NextFunction) => {
|
|
87
|
+
console.error(err);
|
|
88
|
+
res.status(500).json({ error: err.message });
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Exemples avancés
|
|
93
|
+
|
|
94
|
+
#### Avec body et query typés
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
import asyncHandler from "async-express-error";
|
|
98
|
+
|
|
99
|
+
interface CreateUserBody {
|
|
100
|
+
name: string;
|
|
101
|
+
email: string;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
interface SearchQuery {
|
|
105
|
+
q: string;
|
|
106
|
+
limit?: string;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
interface UserListResponse {
|
|
110
|
+
users: User[];
|
|
111
|
+
total: number;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
app.post(
|
|
115
|
+
"/users",
|
|
116
|
+
asyncHandler<Record<string, never>, User, CreateUserBody>(async (req, res) => {
|
|
117
|
+
// req.body est typé comme CreateUserBody
|
|
118
|
+
const { name, email } = req.body;
|
|
119
|
+
const newUser = await createUser({ name, email });
|
|
120
|
+
res.status(201).json(newUser);
|
|
121
|
+
})
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
app.get(
|
|
125
|
+
"/search",
|
|
126
|
+
asyncHandler<Record<string, never>, UserListResponse, never, SearchQuery>(
|
|
127
|
+
async (req, res) => {
|
|
128
|
+
// req.query est typé comme SearchQuery
|
|
129
|
+
const { q, limit } = req.query;
|
|
130
|
+
const users = await searchUsers(q, parseInt(limit || "10"));
|
|
131
|
+
res.json({ users, total: users.length });
|
|
132
|
+
}
|
|
133
|
+
)
|
|
134
|
+
);
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
#### Avec plusieurs middlewares
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
const validateUser = asyncHandler(async (req, res, next) => {
|
|
141
|
+
const user = await getUserByToken(req.headers.authorization);
|
|
142
|
+
req.user = user;
|
|
143
|
+
next();
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
app.get(
|
|
147
|
+
"/protected",
|
|
148
|
+
validateUser,
|
|
149
|
+
asyncHandler(async (req, res) => {
|
|
150
|
+
res.json({ message: "Accès autorisé", user: req.user });
|
|
151
|
+
})
|
|
152
|
+
);
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## API
|
|
156
|
+
|
|
157
|
+
### `asyncHandler(fn)`
|
|
158
|
+
|
|
159
|
+
Enveloppe une fonction asynchrone Express pour capturer automatiquement les erreurs.
|
|
160
|
+
|
|
161
|
+
#### Paramètres de type générique
|
|
162
|
+
|
|
163
|
+
- `P` - Type des paramètres de route (`req.params`)
|
|
164
|
+
- `ResBody` - Type du corps de réponse (`res.json()`)
|
|
165
|
+
- `ReqBody` - Type du corps de requête (`req.body`)
|
|
166
|
+
- `ReqQuery` - Type des paramètres de requête (`req.query`)
|
|
167
|
+
|
|
168
|
+
#### Paramètres
|
|
169
|
+
|
|
170
|
+
- `fn` : `AsyncRequestHandler<P, ResBody, ReqBody, ReqQuery>` - La fonction asynchrone à envelopper
|
|
171
|
+
|
|
172
|
+
#### Retourne
|
|
173
|
+
|
|
174
|
+
Une fonction middleware Express qui gère automatiquement les erreurs.
|
|
175
|
+
|
|
176
|
+
## Contribution
|
|
177
|
+
|
|
178
|
+
Les contributions sont les bienvenues !
|
|
179
|
+
|
|
180
|
+
1. Fork le projet
|
|
181
|
+
2. Créez votre branche (`git checkout -b feature/AmazingFeature`)
|
|
182
|
+
3. Committez vos changements (`git commit -m 'Add some AmazingFeature'`)
|
|
183
|
+
4. Push vers la branche (`git push origin feature/AmazingFeature`)
|
|
184
|
+
5. Ouvrez une Pull Request
|
|
185
|
+
|
|
186
|
+
### Développement local
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
# Installation des dépendances
|
|
190
|
+
npm install
|
|
191
|
+
|
|
192
|
+
# Compilation TypeScript
|
|
193
|
+
npm run build
|
|
194
|
+
|
|
195
|
+
# Lancer les tests
|
|
196
|
+
npm test
|
|
197
|
+
|
|
198
|
+
# Lancer les tests en mode watch
|
|
199
|
+
npm run test:watch
|
|
200
|
+
|
|
201
|
+
# Linter
|
|
202
|
+
npm run lint
|
|
203
|
+
|
|
204
|
+
# Formater le code
|
|
205
|
+
npm run format
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## CI/CD
|
|
209
|
+
|
|
210
|
+
Ce projet utilise GitHub Actions pour l'intégration et le déploiement continus.
|
|
211
|
+
|
|
212
|
+
### Workflows
|
|
213
|
+
|
|
214
|
+
- **CI** : Exécute les tests, le linting et le build sur chaque PR/push
|
|
215
|
+
- **Publish** : Publie automatiquement sur npm et crée une release GitHub
|
|
216
|
+
|
|
217
|
+
### Publier une nouvelle version
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
# Créer un nouveau tag (patch, minor, ou major)
|
|
221
|
+
npm version patch
|
|
222
|
+
|
|
223
|
+
# Pousser le tag
|
|
224
|
+
git push origin main --tags
|
|
225
|
+
|
|
226
|
+
# GitHub Actions publie automatiquement sur npm !
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
⚠️ **Configuration requise** : Ajouter le secret `NPM_TOKEN` dans les paramètres GitHub du repository. Voir [NPM_SETUP.md](.github/NPM_SETUP.md) pour les instructions.
|
|
230
|
+
|
|
231
|
+
## Licence
|
|
232
|
+
|
|
233
|
+
Ce projet est sous licence MIT. Voir le fichier [LICENSE](LICENSE) pour plus de détails.
|
|
234
|
+
|
|
235
|
+
## Changelog
|
|
236
|
+
|
|
237
|
+
### 2.0.0
|
|
238
|
+
|
|
239
|
+
- ✨ Support TypeScript complet avec types génériques
|
|
240
|
+
- 🧪 Suite de tests Jest complète
|
|
241
|
+
- 🔧 Configuration ESLint + Prettier
|
|
242
|
+
- 📦 Exports améliorés pour CommonJS et ESM
|
|
243
|
+
- 📝 Documentation TypeScript améliorée
|
|
244
|
+
|
|
245
|
+
### 1.0.6
|
|
246
|
+
|
|
247
|
+
- Version initiale avec support JavaScript
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Request, Response, NextFunction } from "express";
|
|
2
|
+
/**
|
|
3
|
+
* Type pour une fonction handler Express asynchrone
|
|
4
|
+
*/
|
|
5
|
+
export type AsyncRequestHandler = (req: Request, res: Response, next: NextFunction) => Promise<void> | Promise<unknown>;
|
|
6
|
+
/**
|
|
7
|
+
* Enveloppe une fonction asynchrone pour gérer les erreurs de manière centralisée.
|
|
8
|
+
* Capture les erreurs et les transmet au middleware next() d'Express.
|
|
9
|
+
*
|
|
10
|
+
* @param fn - La fonction asynchrone à envelopper
|
|
11
|
+
* @returns Une fonction enveloppée qui gère les erreurs automatiquement
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import express from "express";
|
|
16
|
+
* import asyncHandler from "async-express-error";
|
|
17
|
+
*
|
|
18
|
+
* const app = express();
|
|
19
|
+
*
|
|
20
|
+
* app.get(
|
|
21
|
+
* "/users/:id",
|
|
22
|
+
* asyncHandler(async (req, res) => {
|
|
23
|
+
* const user = await getUserById(req.params.id);
|
|
24
|
+
* res.json(user);
|
|
25
|
+
* })
|
|
26
|
+
* );
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
declare function asyncHandler(fn: AsyncRequestHandler): (req: Request, res: Response, next: NextFunction) => void;
|
|
30
|
+
export default asyncHandler;
|
|
31
|
+
export { asyncHandler };
|
|
32
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE1D;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAChC,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,YAAY,KACf,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,iBAAS,YAAY,CACnB,EAAE,EAAE,mBAAmB,GACtB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,KAAK,IAAI,CAI3D;AAED,eAAe,YAAY,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.asyncHandler = asyncHandler;
|
|
4
|
+
/**
|
|
5
|
+
* Enveloppe une fonction asynchrone pour gérer les erreurs de manière centralisée.
|
|
6
|
+
* Capture les erreurs et les transmet au middleware next() d'Express.
|
|
7
|
+
*
|
|
8
|
+
* @param fn - La fonction asynchrone à envelopper
|
|
9
|
+
* @returns Une fonction enveloppée qui gère les erreurs automatiquement
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import express from "express";
|
|
14
|
+
* import asyncHandler from "async-express-error";
|
|
15
|
+
*
|
|
16
|
+
* const app = express();
|
|
17
|
+
*
|
|
18
|
+
* app.get(
|
|
19
|
+
* "/users/:id",
|
|
20
|
+
* asyncHandler(async (req, res) => {
|
|
21
|
+
* const user = await getUserById(req.params.id);
|
|
22
|
+
* res.json(user);
|
|
23
|
+
* })
|
|
24
|
+
* );
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
function asyncHandler(fn) {
|
|
28
|
+
return (req, res, next) => {
|
|
29
|
+
Promise.resolve(fn(req, res, next)).catch(next);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
exports.default = asyncHandler;
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AA2CS,oCAAY;AAhCrB;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAS,YAAY,CACnB,EAAuB;IAEvB,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAQ,EAAE;QAC9B,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAClD,CAAC,CAAC;AACJ,CAAC;AAED,kBAAe,YAAY,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "async-express-error",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Simplifiez la gestion des erreurs pour les fonctions asynchrones dans Node.js et Express.",
|
|
5
|
-
"main": "index.js",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Simplifiez la gestion des erreurs pour les fonctions asynchrones dans Node.js et Express avec un support TypeScript complet.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist/**/*",
|
|
9
|
+
"LICENSE",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"build:watch": "tsc --watch",
|
|
15
|
+
"test": "jest",
|
|
16
|
+
"test:watch": "jest --watch",
|
|
17
|
+
"test:coverage": "jest --coverage",
|
|
18
|
+
"lint": "eslint src/**/*.ts __tests__/**/*.ts",
|
|
19
|
+
"lint:fix": "eslint src/**/*.ts __tests__/**/*.ts --fix",
|
|
20
|
+
"format": "prettier --write \"src/**/*.ts\" \"__tests__/**/*.ts\"",
|
|
21
|
+
"format:check": "prettier --check \"src/**/*.ts\" \"__tests__/**/*.ts\"",
|
|
22
|
+
"clean": "rm -rf dist coverage",
|
|
23
|
+
"prepublishOnly": "npm run clean && npm run build && npm test",
|
|
24
|
+
"postversion": "git push && git push --tags"
|
|
25
|
+
},
|
|
6
26
|
"repository": {
|
|
7
27
|
"type": "git",
|
|
8
28
|
"url": "git+https://github.com/J2mCoder/async-express-error.git"
|
|
@@ -13,9 +33,44 @@
|
|
|
13
33
|
"errors",
|
|
14
34
|
"express",
|
|
15
35
|
"middleware",
|
|
16
|
-
"error-handling"
|
|
36
|
+
"error-handling",
|
|
37
|
+
"typescript",
|
|
38
|
+
"promise",
|
|
39
|
+
"catch",
|
|
40
|
+
"nodejs"
|
|
17
41
|
],
|
|
18
42
|
"author": "J2mCoder",
|
|
19
43
|
"license": "MIT",
|
|
20
|
-
"private": false
|
|
44
|
+
"private": false,
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=14.0.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/express": "^4.17.21",
|
|
50
|
+
"@types/jest": "^29.5.12",
|
|
51
|
+
"@types/node": "^20.11.24",
|
|
52
|
+
"@typescript-eslint/eslint-plugin": "^7.1.0",
|
|
53
|
+
"@typescript-eslint/parser": "^7.1.0",
|
|
54
|
+
"eslint": "^8.57.0",
|
|
55
|
+
"eslint-config-prettier": "^9.1.0",
|
|
56
|
+
"jest": "^29.7.0",
|
|
57
|
+
"prettier": "^3.2.5",
|
|
58
|
+
"ts-jest": "^29.1.2",
|
|
59
|
+
"typescript": "^5.3.3"
|
|
60
|
+
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"express": "^4.0.0 || ^5.0.0"
|
|
63
|
+
},
|
|
64
|
+
"exports": {
|
|
65
|
+
".": {
|
|
66
|
+
"import": {
|
|
67
|
+
"types": "./dist/index.d.ts",
|
|
68
|
+
"default": "./dist/index.js"
|
|
69
|
+
},
|
|
70
|
+
"require": {
|
|
71
|
+
"types": "./dist/index.d.ts",
|
|
72
|
+
"default": "./dist/index.js"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
21
76
|
}
|
package/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Enveloppe une fonction asynchrone pour gérer les erreurs de manière centralisée.
|
|
3
|
-
* @param {Function} fn - La fonction asynchrone à envelopper.
|
|
4
|
-
* @returns {Function} - La fonction enveloppée.
|
|
5
|
-
*/
|
|
6
|
-
const asyncHandler =
|
|
7
|
-
(fn) =>
|
|
8
|
-
(...args) => {
|
|
9
|
-
const next = args[args.length - 1]
|
|
10
|
-
return Promise.resolve(fn(...args)).catch(next)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
module.exports = asyncHandler
|