clean-error-maker 1.0.0 → 1.0.3
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 +51 -50
- package/index.js +17 -17
- package/package.json +14 -3
- package/test/demo.js +0 -17
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Aayush
|
|
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
|
|
13
|
+
all 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
|
|
21
|
+
THE SOFTWARE.
|
package/Readme.md
CHANGED
|
@@ -1,50 +1,51 @@
|
|
|
1
|
-
# clean-error-maker
|
|
2
|
-
|
|
3
|
-
A tiny utility for creating consistent, structured HTTP errors in Node.js and Express.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```
|
|
8
|
-
npm install clean-error-maker
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Usage
|
|
12
|
-
|
|
13
|
-
```js
|
|
14
|
-
const { httpError } = require("clean-error-maker");
|
|
15
|
-
|
|
16
|
-
throw httpError(404, "User not found");
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## Example Output
|
|
20
|
-
|
|
21
|
-
```json
|
|
22
|
-
{
|
|
23
|
-
"status": 404,
|
|
24
|
-
"message": "User not found",
|
|
25
|
-
"success": false,
|
|
26
|
-
"timestamp": "2025-12-12T15:00:10.000Z",
|
|
27
|
-
"data": null
|
|
28
|
-
}
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
## With Extra Data
|
|
32
|
-
|
|
33
|
-
```js
|
|
34
|
-
throw httpError(400, "Invalid input", { field: "email" });
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
1
|
+
# clean-error-maker
|
|
2
|
+
|
|
3
|
+
A tiny utility for creating consistent, structured HTTP errors in Node.js and Express-js.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
npm install clean-error-maker
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
const { httpError } = require("clean-error-maker");
|
|
15
|
+
|
|
16
|
+
throw httpError(404, "User not found");
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Example Output
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"status": 404,
|
|
24
|
+
"message": "User not found",
|
|
25
|
+
"success": false,
|
|
26
|
+
"timestamp": "2025-12-12T15:00:10.000Z",
|
|
27
|
+
"data": null
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## With Extra Data
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
throw httpError(400, "Invalid input", { field: "email" });
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
## Why Use This?
|
|
39
|
+
|
|
40
|
+
* Consistent error structure
|
|
41
|
+
* Ready for Express API responses
|
|
42
|
+
* Includes timestamp
|
|
43
|
+
* Preserves stack trace
|
|
44
|
+
* Supports custom data
|
|
45
|
+
|
|
46
|
+
## Ideal For
|
|
47
|
+
|
|
48
|
+
* Backend APIs
|
|
49
|
+
* Express.js apps
|
|
50
|
+
* Microservices
|
|
51
|
+
* Clean error handling
|
package/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
// clean-error-maker
|
|
2
|
-
|
|
3
|
-
function httpError(status = 500, message = "Something went wrong", data = null) {
|
|
4
|
-
const error = new Error(message);
|
|
5
|
-
|
|
6
|
-
error.status = status;
|
|
7
|
-
error.success = false;
|
|
8
|
-
error.timestamp = new Date().toISOString();
|
|
9
|
-
|
|
10
|
-
if (data) {
|
|
11
|
-
error.data = data;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return error;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export default { httpError };
|
|
1
|
+
// clean-error-maker
|
|
2
|
+
|
|
3
|
+
function httpError(status = 500, message = "Something went wrong", data = null) {
|
|
4
|
+
const error = new Error(message);
|
|
5
|
+
|
|
6
|
+
error.status = status;
|
|
7
|
+
error.success = false;
|
|
8
|
+
error.timestamp = new Date().toISOString();
|
|
9
|
+
|
|
10
|
+
if (data) {
|
|
11
|
+
error.data = data;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return error;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default { httpError };
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clean-error-maker",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "A tiny utility to create consistent and structured HTTP errors for Node.js and Express applications.",
|
|
5
5
|
"main": "index.js",
|
|
6
|
-
"type":"module",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"files": [
|
|
8
|
+
"index.js"
|
|
9
|
+
],
|
|
7
10
|
"keywords": [
|
|
8
11
|
"http-error",
|
|
9
12
|
"error",
|
|
@@ -13,6 +16,14 @@
|
|
|
13
16
|
"error-handler",
|
|
14
17
|
"structured-error"
|
|
15
18
|
],
|
|
16
|
-
"
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/Aayushsah6969/clean-error-maker.git"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://github.com/Aayushsah6969/clean-error-maker#readme",
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/Aayushsah6969/clean-error-maker/issues"
|
|
26
|
+
},
|
|
27
|
+
"author": "Aayush Kumar Sah",
|
|
17
28
|
"license": "MIT"
|
|
18
29
|
}
|
package/test/demo.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// test/demo.js
|
|
2
|
-
import { join } from "path";
|
|
3
|
-
const { httpError } = require(join("..", "index"));
|
|
4
|
-
|
|
5
|
-
try {
|
|
6
|
-
throw httpError(400, "Invalid input", { field: "email" });
|
|
7
|
-
} catch (err) {
|
|
8
|
-
// Collect all own property names (includes stack & message)
|
|
9
|
-
const out = {};
|
|
10
|
-
Object.getOwnPropertyNames(err).forEach((k) => {
|
|
11
|
-
out[k] = err[k];
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
// Print a clean JSON representation
|
|
15
|
-
console.log("=== Serialized error ===");
|
|
16
|
-
console.log(JSON.stringify(out, null, 2));
|
|
17
|
-
}
|