Installations
npm install baseerr
Developer Guide
Typescript
Yes
Module System
ESM
Node Version
16.20.2
NPM Version
8.19.4
Score
72.9
Supply Chain
99.4
Quality
79.6
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (100%)
Developer
tjmehta
Download Statistics
Total Downloads
80,811
Last Day
11
Last Week
108
Last Month
922
Last Year
21,332
GitHub Statistics
2 Stars
32 Commits
3 Watching
13 Branches
1 Contributors
Bundle Size
3.71 kB
Minified
1.48 kB
Minified + Gzipped
Package Meta Information
Latest Version
2.0.6
Package Id
baseerr@2.0.6
Unpacked Size
37.71 kB
Size
8.39 kB
File Count
18
NPM Version
8.19.4
Node Version
16.20.2
Publised On
17 Apr 2024
Total Downloads
Cumulative downloads
Total Downloads
80,811
Last day
-77.6%
11
Compared to previous day
Last week
-41.6%
108
Compared to previous week
Last month
-92.5%
922
Compared to previous month
Last year
13.9%
21,332
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
BaseErr
A solid BaseError class that supports custom properties and wrapping errors
Installation
1npm i --save baseerr
Usage
Create a custom error class
1import BaseError from 'baseerr' 2 3class CustomError extends BaseError {} 4 5const err = new CustomError('boom') 6console.log(err.name // 'CustomError' 7console.log(err.stack) 8// CustomError: boom 9// anonymous (filename:5:17)
Wrap an error with a custom error class
1import BaseError from 'baseerr' 2 3class CustomError extends BaseError {} 4 5try { 6 throw new Error('pow') 7} catch (_err) { 8 const err = CustomError.wrap('caught error', _err) 9 console.log(err.stack) 10 // CustomError: caught error 11 // anonymous (filename:8:17) 12 // ---- 13 // Error: pow 14 // anonymous (filename:6:9) 15}
Wrap an error with a custom error class in promise chain
1import BaseError from 'baseerr' 2 3class CustomError extends BaseError {} 4 5Promise.reject(new Error('pow')).catch((err) => 6 CustomError.wrapAndThrow('caught error', err), 7) 8// rejects with: 9// CustomError: caught error 10// anonymous (filename:6:3) 11// ---- 12// Error: pow 13// anonymous (filename:5:16)
Create custom error instance with data properties
1import BaseError from 'baseerr' 2 3class CustomError extends BaseError {} 4 5const err = new CustomError('boom', { foo: 10, bar: 20 }) 6console.log(err.foo) // 10 7console.log(err.bar) // 20 8console.log(err.stack) 9// CustomError: boom 10// anonymous (filename:5:17) 11// { 12// "foo": 10, 13// "bar": 20 14// } 15 16// TypeScripters use BaseError.create if you want to access extended properties with proper typing: 17const err = CustomError.create('boom', { foo: 10, bar: 20 }) 18console.log(err.foo) // 10 19console.log(err.bar) // 20
Create custom api client with robust error handling
1import BaseError from 'baseerr' 2 3class FetchError extends BaseError {} 4class ResponseError extends BaseError {} 5class ApiError extends BaseError {} 6 7class ApiClient { 8 getData() { 9 const url = 'https://localhost:3000' 10 try { 11 const res = await Promise.race([ 12 timeout(2000).then(() => { 13 throw new TimeoutError('request timed out', { statusCode: 504, url }) 14 }), 15 fetch(url).catch( 16 FetchError.wrapAndThrow('network error', { statusCode: 503, url }), 17 ), 18 ]) 19 if (res.statusCode !== 200) { 20 throw new ResponseError('status: ${res.statusCode}', { 21 statusCode: res.statusCode, 22 url, 23 }) 24 } 25 return await res.json() 26 } catch (err) { 27 throw ApiError.wrap(err, { url, statusCode: err.statusCode || 500 }) 28 // ApiError: boom 29 // anonymous (filename:row:col) 30 // { 31 // "url": 'https://localhost:3000', 32 // "statusCode": 504 33 // } 34 // ---- 35 // TimedoutError: request timed out 36 // anonymous (filename:row:col) 37 // { 38 // "url": 'https://localhost:3000', 39 // "statusCode": 504 40 // } 41 } 42 } 43}
Checkout the tests for more examples..
License
MIT
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 0/27 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/npm-publish.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:7: update your workflow using https://app.stepsecurity.io/secureworkflow/tjmehta/baseerr/npm-publish.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:8: update your workflow using https://app.stepsecurity.io/secureworkflow/tjmehta/baseerr/npm-publish.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/tjmehta/baseerr/npm-publish.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/npm-publish.yml:12
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 6 are checked with a SAST tool
Reason
28 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-w8qv-6jwh-64r5
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
Score
2.5
/10
Last Scanned on 2024-12-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More