@statezero/core 0.2.27 → 0.2.28
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/dist/errorHandler.d.ts +21 -0
- package/dist/errorHandler.js +27 -0
- package/dist/flavours/django/errors.js +2 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +4 -1
- package/package.json +1 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Register a global error handler for StateZero errors.
|
|
3
|
+
* Errors still propagate to call sites - this is for side effects like toasts.
|
|
4
|
+
*
|
|
5
|
+
* @param {Function} handler - Callback receiving the error
|
|
6
|
+
* @returns {Function} Unsubscribe function
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* // In a Vue component with access to toast
|
|
10
|
+
* const unsubscribe = onStateZeroError((error) => {
|
|
11
|
+
* toast.error(error.message)
|
|
12
|
+
* })
|
|
13
|
+
* onUnmounted(() => unsubscribe())
|
|
14
|
+
*/
|
|
15
|
+
export function onStateZeroError(handler: Function): Function;
|
|
16
|
+
/**
|
|
17
|
+
* Emit an error to all registered handlers.
|
|
18
|
+
* @param {Error} error - The error that occurred
|
|
19
|
+
*/
|
|
20
|
+
export function emitError(error: Error): void;
|
|
21
|
+
export const errorEmitter: any;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import mitt from 'mitt';
|
|
2
|
+
export const errorEmitter = mitt();
|
|
3
|
+
/**
|
|
4
|
+
* Register a global error handler for StateZero errors.
|
|
5
|
+
* Errors still propagate to call sites - this is for side effects like toasts.
|
|
6
|
+
*
|
|
7
|
+
* @param {Function} handler - Callback receiving the error
|
|
8
|
+
* @returns {Function} Unsubscribe function
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // In a Vue component with access to toast
|
|
12
|
+
* const unsubscribe = onStateZeroError((error) => {
|
|
13
|
+
* toast.error(error.message)
|
|
14
|
+
* })
|
|
15
|
+
* onUnmounted(() => unsubscribe())
|
|
16
|
+
*/
|
|
17
|
+
export function onStateZeroError(handler) {
|
|
18
|
+
errorEmitter.on('error', handler);
|
|
19
|
+
return () => errorEmitter.off('error', handler);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Emit an error to all registered handlers.
|
|
23
|
+
* @param {Error} error - The error that occurred
|
|
24
|
+
*/
|
|
25
|
+
export function emitError(error) {
|
|
26
|
+
errorEmitter.emit('error', error);
|
|
27
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { emitError } from '../../errorHandler.js';
|
|
1
2
|
/**
|
|
2
3
|
* @typedef {Object} IErrorResponse
|
|
3
4
|
* @property {number} status - The HTTP status code.
|
|
@@ -28,6 +29,7 @@ export class StateZeroError extends Error {
|
|
|
28
29
|
this.detail = detail;
|
|
29
30
|
this.status = status;
|
|
30
31
|
Object.setPrototypeOf(this, new.target.prototype);
|
|
32
|
+
emitError(this);
|
|
31
33
|
}
|
|
32
34
|
/**
|
|
33
35
|
* Returns a full error message including the detail.
|
package/dist/index.d.ts
CHANGED
|
@@ -37,4 +37,5 @@ import { setAdapters } from "./reactiveAdaptor.js";
|
|
|
37
37
|
import { wrapReactiveModel } from "./reactiveAdaptor.js";
|
|
38
38
|
import { wrapReactiveQuerySet } from "./reactiveAdaptor.js";
|
|
39
39
|
import { serializeActionPayload } from "./flavours/django/serializers.js";
|
|
40
|
-
|
|
40
|
+
import { onStateZeroError } from "./errorHandler.js";
|
|
41
|
+
export { EventType, PusherEventReceiver, setEventReceiver, getEventReceiver, setNamespaceResolver, setupStateZero, resetStateZero, FileObject, querysetStoreRegistry, modelStoreRegistry, metricRegistry, syncManager, Operation, operationRegistry, Q, StateZeroError, ValidationError, DoesNotExist, PermissionDenied, MultipleObjectsReturned, ASTValidationError, ConfigError, parseStateZeroError, QuerySet, Manager, ResultTuple, Model, setConfig, getConfig, setBackendConfig, initializeEventReceiver, configInstance, getModelClass, initEventHandler, cleanupEventHandler, setAdapters, wrapReactiveModel, wrapReactiveQuerySet, serializeActionPayload, onStateZeroError };
|
package/dist/index.js
CHANGED
|
@@ -20,6 +20,7 @@ import { setAdapters, wrapReactiveModel, wrapReactiveQuerySet, } from "./reactiv
|
|
|
20
20
|
import { syncManager } from "./syncEngine/sync.js";
|
|
21
21
|
import { initEventHandler, cleanupEventHandler, } from "./syncEngine/stores/operationEventHandlers.js";
|
|
22
22
|
import { resetStateZero } from "./reset.js";
|
|
23
|
+
import { onStateZeroError } from "./errorHandler.js";
|
|
23
24
|
// Explicitly export everything
|
|
24
25
|
export {
|
|
25
26
|
// Core event receivers
|
|
@@ -39,4 +40,6 @@ setConfig, getConfig, setBackendConfig, initializeEventReceiver, configInstance,
|
|
|
39
40
|
// Reactivity framework integration
|
|
40
41
|
initEventHandler, cleanupEventHandler, setAdapters, wrapReactiveModel, wrapReactiveQuerySet,
|
|
41
42
|
// Action utilities
|
|
42
|
-
serializeActionPayload,
|
|
43
|
+
serializeActionPayload,
|
|
44
|
+
// Error handling
|
|
45
|
+
onStateZeroError, };
|
package/package.json
CHANGED