@momsfriendlydevco/cowboy 1.1.1 → 1.2.0
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/lib/cowboy.js +18 -3
- package/package.json +1 -1
package/lib/cowboy.js
CHANGED
|
@@ -240,16 +240,31 @@ export class Cowboy {
|
|
|
240
240
|
response = res.end(response);
|
|
241
241
|
}
|
|
242
242
|
} catch (e) {
|
|
243
|
-
let errorText =
|
|
243
|
+
let errorText =
|
|
244
|
+
!e ? 'An unknown error has occured'
|
|
245
|
+
: typeof e == 'string' ? e
|
|
246
|
+
: e instanceof Error ? e.toString().replace(/^Error: /, '')
|
|
247
|
+
: e.error && typeof e.error == 'string' ? e.error
|
|
248
|
+
: e.err && typeof e.err == 'string' ? e.err
|
|
249
|
+
: e?.data && typeof e.data == 'string' ? e.data
|
|
250
|
+
: e?.data?.errmsg && typeof e.data.errmsg == 'string' ? e.data.errmsg
|
|
251
|
+
: e?.data?.error && typeof e.data.error == 'string' ? e.data.error
|
|
252
|
+
: e?.data?.err && typeof e.data.err == 'string' ? e.data.err
|
|
253
|
+
: e?.data?.statusText && typeof e.data.statusText == 'string' ? e.data.statusText
|
|
254
|
+
: e?.status === -1 ? 'Server connection failed'
|
|
255
|
+
: typeof e == 'function' && e.toString() !== '[object Object]' ? e.toString()
|
|
256
|
+
: e?.code && e?.message && typeof e.code == 'string' && typeof e.message == 'string' ? `${e.code}: ${e.message}` // Supabase error objects
|
|
257
|
+
: 'An unknown error has occured';
|
|
244
258
|
|
|
245
259
|
debug('Error thrown', e);
|
|
260
|
+
debug('Extracted error text digest', {errorText});
|
|
246
261
|
|
|
247
262
|
// Form: '404: Not found'
|
|
248
263
|
if (/^(\d{3}):/.test(errorText)) {
|
|
249
264
|
let errorBits = /^(?<status>\d{3}):?(?<text>.*)$/.exec(errorText).groups;
|
|
250
265
|
res.status(errorBits.status).send(errorBits.text);
|
|
251
|
-
} else { // Generic error - assume 400
|
|
252
|
-
res.status(400).send(
|
|
266
|
+
} else { // Generic error code - assume 400
|
|
267
|
+
res.status(400).send(errorText);
|
|
253
268
|
}
|
|
254
269
|
|
|
255
270
|
response = res;
|