@@ -14,26 +14,48 @@ Install with [NPM](https://npmjs.org/):
14
14
## Usage
15
15
16
16
``` js
17
- const { RedisError , ReplyError } = require (' redis-errors' );
17
+ const { ReplyError , InterruptError } = require (' redis-errors' );
18
18
19
19
// Using async await
20
20
try {
21
- return client .set (' foo' ) // Missing value
21
+ await client .set (' foo' ) // Missing value
22
22
} catch (err) {
23
+ if (err instanceof InterruptError) {
24
+ console .error (' Command might have been processed' )
25
+ }
23
26
if (err instanceof ReplyError) {
24
- console . log (err)
27
+ // ...
25
28
}
26
29
throw err
27
30
}
31
+
32
+ // Using callbacks
33
+ client .set (' foo' , (err , res ) => {
34
+ if (err) {
35
+ if (err instanceof InterruptError) {
36
+ // ...
37
+ }
38
+ }
39
+ })
28
40
```
29
41
30
42
### Error classes
31
43
32
- * ` RedisError ` sub class of Error
33
- * ` ReplyError ` sub class of RedisError
34
- * ` ParserError ` sub class of RedisError
35
-
36
- All Redis errors will be returned as ` ReplyErrors ` while a parser error is returned as ` ParserError ` .
44
+ * ` RedisError ` subclass of Error
45
+ * ` ReplyError ` subclass of RedisError
46
+ * ` ParserError ` subclass of RedisError
47
+ * ` AbortError ` subclass of RedisError
48
+ * ` InterruptError ` subclass of AbortError
49
+
50
+ * All errors returned by NodeRedis (client) are ` RedisError ` s.
51
+ * All errors returned by Redis itself (server) will be a ` ReplyError ` .
52
+ * Parsing errors are returned as ` ParserError ` . * Note:* Please report these!
53
+ * If a command was not executed but rejected, it'll return a ` AbortError ` .
54
+ * All executed commands that could not fulfill (e.g. network drop while
55
+ executing) return a ` InterruptError ` .
56
+ * Note:* Interrupt errors can happen for multiple reasons that are out of the
57
+ scope of NodeRedis itself. There is nothing that can be done on library side
58
+ to prevent those.
37
59
38
60
## License
39
61
0 commit comments