@fullstackunicorn/initialize 1.0.8 → 1.0.9

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.
Files changed (2) hide show
  1. package/index.js +22 -5
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -113,10 +113,9 @@ globalThis.F3.throw = (...args) => { throw new F3Error(F3.service, ...args) }
113
113
  globalThis.F3.err = {}
114
114
  globalThis.F3.err.is500 = status => !!status && status >= 500
115
115
  globalThis.F3.err.is400 = status => !!status && status >= 400 && status < 500
116
-
117
- globalThis.F3.err.toObj = err => {
118
- const base = { name:err.name, message:err.message, stack:err.stack }
119
- try { return Object.assign(base, Object.fromEntries(Object.entries(err)))}
116
+ globalThis.F3.err.toObj = err => {
117
+ const base = { name: err.name, message: err.message, stack: err.stack }
118
+ try { return Object.assign(base, Object.fromEntries(Object.entries(err))) }
120
119
  catch { return base }
121
120
  }
122
121
  globalThis.F3.err.toStr = err => {
@@ -127,7 +126,25 @@ globalThis.F3.err.toStr = err => {
127
126
  }
128
127
  globalThis.F3.err.logs = err => {
129
128
  if (err instanceof F3Error) console.error(F3.obj.toStr(err))
130
- else console.error('non-F3-error',F3.obj.toStr(err))
129
+ else console.error('non-F3-error', F3.obj.toStr(err))
130
+ }
131
+ globalThis.F3.err.isOffline = (error) => {
132
+ if (!F3.obj.isGood(error)) return false
133
+ return (
134
+ error.code === 'ECONNABORTED' ||
135
+ error.code === 'ERR_NETWORK' ||
136
+ error.message.includes('Network Error') ||
137
+ error.message.includes('timeout')
138
+ )
139
+ }
140
+ globalThis.F3.err.cache = async (error, cached) => {
141
+ if (!F3.err.isOffline(error)) return { isError: true }
142
+ if (cached) return cached
143
+ return { isOffline: true }
144
+ }
145
+ globalThis.F3.err.handle = (error) => {
146
+ if (!F3.err.isOffline(error)) return { isError: true }
147
+ return { isOffline: true }
131
148
  }
132
149
 
133
150
  globalThis.F3.catch = {}
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.8",
2
+ "version": "1.0.9",
3
3
  "name": "@fullstackunicorn/initialize",
4
4
  "author": "lucanigido (https://fullstackunicorn.dev/author/lucanigido)",
5
5
  "description": "A collection of global utility functions for JavaScript/Node.js projects (type checks, string helpers, logging, etc.). Side-effect import extends globals.",