8000 feat: add getErrorDetails helper; update version to 1.0.4 · dmltdev/mongo-error-codes@5e74925 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5e74925

Browse files
committed
feat: add getErrorDetails helper; update version to 1.0.4
1 parent 340f79c commit 5e74925

File tree

4 files changed

+105
-1
lines changed

4 files changed

+105
-1
lines changed

CONTRIBUTING.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Contributing to mongo-error-codes
2+
3+
Thank you for your interest in contributing to mongo-error-codes! This document provides guidelines and instructions for contributing.
4+
5+
## Getting Started
6+
7+
1. **Fork the Repository**
8+
Fork the [mongo-error-codes](https://github.com/dmltdev/mongo-error-codes) repository to your GitHub account.
9+
10+
2. **Clone Your Fork**
11+
12+
```sh
13+
git clone https://github.com/dmltdev/mongo-error-codes.git
14+
cd mongo-error-codes
15+
```
16+
17+
3. **Install Dependencies**
18+
19+
```sh
20+
npm install
21+
```
22+
23+
4. **Build the Project**
24+
```sh
25+
npm run build
26+
```
27+
28+
## Development
29+
30+
- **Branch Naming**
31+
Create a new branch for your feature or bugfix:
32+
33+
```sh
34+
git checkout -b feature/your-feature-name
35+
```
36+
37+
- **Code Style**
38+
Ensure your code follows the project's style guidelines. Consider using ESLint and Prettier.
39+
40+
- **Testing**
41+
Run tests to ensure your changes work as expected:
42+
```sh
43+
npm test
44+
```
45+
46+
## Submitting a Pull Request
47+
48+
1. **Push Your Changes**
49+
50+
```sh
51+
git push origin feature/your-feature-name
52+
```
53+
54+
2. **Create a Pull Request**
55+
Go to the [mongo-error-codes repository](https://github.com/dmltdev/mongo-error-codes) and create a pull request from your fork.
56+
57+
3. **Describe Your Changes**
58+
Provide a clear description of your changes and why they are needed.
59+
60+
4. **Wait for Review**
61+
Your PR will be reviewed by maintainers. Be ready to make changes if requested.
62+
63+
## Additional Guidelines
64+
65+
- **Commit Messages**
66+
Use clear, descriptive commit messages.
67+
68+
- **Documentation**
69+
Update documentation (e.g., README, API docs) if your changes affect the public API.
70+
71+
- **License**
72+
By contributing, you agree that your contributions will be licensed under the project's MIT License.
73+
74+
---
75+
76+
Thank you for contributing!

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mongo-error-codes",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"repository": "https://github.com/dmltdev/mongo-error-codes",
55
"description": "A minimal library of MongoDB error codes, names, and helper utilities for error handling, logging, and developer tools.",
66
"main": "dist/index.js",

readme.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ import { isKnownErrorCode } from "mongo-error-codes";
8585
console.log(isKnownErrorCode(11000)); // true
8686
```
8787

88+
#### `getErrorDetails(input: number | string): { code: number; name: string; description?: string } | undefined`
89+
90+
Returns the full error object (code, name, description) for a given error code or name.
91+
92+
```ts
93+
import { getErrorDetails } from "mongo-error-codes";
94+
console.log(getErrorDetails(11000));
95+
// { code: 11000, name: "DuplicateKey", description: "Duplicate key error collection" }
96+
console.log(getErrorDetails("DuplicateKey"));
97+
// { code: 11000, name: "DuplicateKey", description: "Duplicate key error collection" }
98+
```
99+
88100
### Data Structures
89101

90102
#### `MongoErrorCodes` (enum)

src/helpers/helpers.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,19 @@ export function getErrorDescription(code: number): string | undefined {
4242
export function isKnownErrorCode(code: number): boolean {
4343
return MongoCodeErrorMap.has(code);
4444
}
45+
46+
/**
47+
* Get the full error details (code, name, description) for a given error code or name.
48+
*
49+
* @param input - The error code (number) or error name (string).
50+
* @returns The full error object or undefined if not found.
51+
*/
52+
export function getErrorDetails(
53+
input: number | string
54+
): { code: number; name: string; description?: string } | undefined {
55+
if (typeof input === "number") {
56+
return MongoCodeErrorMap.get(input);
57+
} else {
58+
return MongoNameErrorMap.get(input);
59+
}
60+
}

0 commit comments

Comments
 (0)
0