Skip to content

Commit 0825ee1

Browse files
committed
feat(api): export error classes and interfaces for advanced usage 🚀
- Add advanced error handling documentation with import examples and instanceof checks - Export error classes for specific error handling (ValidationError, TokenExpiredError, etc.) - Export TypeScript interfaces for type safety (JWTOptions, EncryptionAlgo, etc.) - Update version to 1.4.1 for patch release
1 parent 2e46919 commit 0825ee1

File tree

4 files changed

+95
-1
lines changed

4 files changed

+95
-1
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
---
99

10+
## [1.4.1] - 2025-09-06
11+
12+
### Added
13+
- **Error class exports**: Export custom error classes for advanced error handling
14+
- **Interface type exports**: Export TypeScript interfaces for type safety and development
15+
- **Advanced error handling documentation**: Examples with import statements and instanceof checks
16+
17+
### Changed
18+
- **Type safety**: Exported interfaces enable better TypeScript development experience
19+
20+
---
21+
1022
## [1.4.0] - 2025-09-06
1123

1224
### Added

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ Extracts data from token, throws on error.
181181

182182
## ❌ Error Handling
183183

184+
### Basic Error Handling
185+
184186
```javascript
185187
// Using verify() - returns boolean
186188
const isValid = jwt.verify(token)
@@ -205,6 +207,58 @@ try {
205207
}
206208
```
207209

210+
### Advanced Error Handling
211+
212+
```javascript
213+
import {
214+
SecureJWT,
215+
TokenExpiredError,
216+
ValidationError,
217+
EncryptionError,
218+
DecryptionError,
219+
PayloadTooLargeError,
220+
TokenInvalidError,
221+
VersionMismatchError
222+
} from '@neabyte/secure-jwt'
223+
224+
const jwt = new SecureJWT({
225+
secret: 'your-secret-key',
226+
expireIn: '1h'
227+
})
228+
229+
// Specific error handling
230+
try {
231+
jwt.verifyStrict(token)
232+
console.log('Token is valid')
233+
} catch (error) {
234+
if (error instanceof TokenExpiredError) {
235+
console.log('Token expired:', error.message)
236+
// Handle expired token - redirect to login
237+
} else if (error instanceof ValidationError) {
238+
console.log('Invalid token format:', error.message)
239+
// Handle invalid format - show error message
240+
} else if (error instanceof VersionMismatchError) {
241+
console.log('Token version mismatch:', error.message)
242+
// Handle version mismatch - force re-login
243+
} else if (error instanceof PayloadTooLargeError) {
244+
console.log('Payload too large:', error.message)
245+
// Handle oversized payload - reduce data size
246+
} else {
247+
console.log('Unknown error:', error.message)
248+
}
249+
}
250+
251+
// Error properties
252+
try {
253+
jwt.verifyStrict(token)
254+
} catch (error) {
255+
console.log('Error type:', error.constructor.name)
256+
console.log('Error code:', error.code) // e.g., 'TOKEN_EXPIRED'
257+
console.log('Status code:', error.statusCode) // e.g., 401
258+
console.log('Error message:', error.message) // Human-readable message
259+
}
260+
```
261+
208262
---
209263

210264
## 🏗️ Architecture

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@neabyte/secure-jwt",
33
"description": "Secure JWT with AES-256-GCM & ChaCha20-Poly1305 encryption, built-in caching, tamper detection, and TypeScript support",
4-
"version": "1.4.0",
4+
"version": "1.4.1",
55
"type": "module",
66
"main": "./dist/index.js",
77
"types": "./dist/index.d.ts",

src/index.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,3 +327,31 @@ export default class SecureJWT {
327327
}
328328
}
329329
}
330+
331+
/**
332+
* Export interfaces for external use
333+
* @see {@link @interfaces/index}
334+
*/
335+
export type {
336+
EncryptionAlgo,
337+
JWTOptions,
338+
JWTPayload,
339+
KeyDerivationAlgo,
340+
TimeUnit
341+
} from '@interfaces/index'
342+
343+
/**
344+
* Export error classes for external use
345+
* @see {@link @utils/index}
346+
*/
347+
export {
348+
ValidationError,
349+
EncryptionError,
350+
DecryptionError,
351+
PayloadTooLargeError,
352+
TokenExpiredError,
353+
VersionMismatchError,
354+
TokenInvalidError,
355+
TimeFormatError,
356+
SecretKeyError
357+
} from '@utils/index'

0 commit comments

Comments
 (0)