|
24 | 24 |
|
25 | 25 | ## Members |
26 | 26 |
|
27 | | - - `id` - lderror deined error code. |
28 | | - - `message` - custom error message (optional) |
29 | | - - `stack` - stacktrace (optional) |
30 | | - - `code` - http status code, if applicable (optional) |
31 | | - - `log` - should this error be logged. default false. |
| 27 | + - `id`: lderror deined error code. |
| 28 | + - `message`: custom error message (optional) |
| 29 | + - `stack`: stacktrace (optional) |
| 30 | + - `code`: http status code, if applicable (optional) |
| 31 | + - `log`: should this error be logged. default false. |
| 32 | + - `error`: an Error object constructed |
32 | 33 |
|
33 | 34 |
|
34 | 35 | ## Helper Functions |
@@ -57,6 +58,11 @@ lderror exports several help functions for making use lderror easier: |
57 | 58 | - options: |
58 | 59 | - `o`: user-defined object returned by `rule(id)`. |
59 | 60 | - `e`: the original error object. |
| 61 | + - `lderror.eventHandler`: helper event handler. See below section for more information. |
| 62 | + - `eventHandler` provides two member functions: |
| 63 | + - `error(evt)`: handler for `error` event. |
| 64 | + - `rejection(evt)`: handler for `unhandledrejection` event. |
| 65 | + - for both functions, return true if `lderror` is handled. otherwise false. |
60 | 66 |
|
61 | 67 |
|
62 | 68 | ### Error Handler |
@@ -95,11 +101,27 @@ Work along with `@plotdb/block` + `ldcvmgr`: |
95 | 101 | .catch handler |
96 | 102 |
|
97 | 103 |
|
| 104 | +## error / unhandledrejection events |
| 105 | + |
| 106 | +You can use `lderror.eventHandler.error` and `lderror.eventHandler.rejection` to take care of lderror related errors: |
| 107 | + |
| 108 | + window.addEventListenen("error", lderror.eventHandler.error); |
| 109 | + window.addEventListenen("unhandledrejection", lderror.eventHandler.rejection); |
| 110 | + |
| 111 | +These handlers simply check if incoming error is a lderror with original error object; if it is, additional information is logged and the original error object will be thrown for showing stacktrace information. |
| 112 | + |
| 113 | +To wrap them along with your own event handler, test its return value and proceed if it returns `false`: |
| 114 | + |
| 115 | + window.addEventListenen("error", function(evt) { |
| 116 | + if(!lderror.eventHandler.error) { /* your own handler */ } |
| 117 | + }); |
| 118 | + |
| 119 | + |
98 | 120 | ## Customized information |
99 | 121 |
|
100 | 122 | Additional information can be added if needed: |
101 | 123 |
|
102 | | - - redirect - instruct a redirect url in order to proper take care of this error. |
| 124 | + - redirect - instruct a redirect url in order to proper take care of this error. |
103 | 125 |
|
104 | 126 |
|
105 | 127 | ## License |
|
0 commit comments