@rnw-community/rxjs-errors 0.52.0 → 0.53.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/package.json +3 -3
- package/readme.md +39 -30
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rnw-community/rxjs-errors",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.53.0",
|
|
4
4
|
"description": "RxJS errors utils",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rxjs error operator",
|
|
@@ -38,13 +38,13 @@
|
|
|
38
38
|
"clear": "rm -rf coverage && rm -rf dist && rm -f *.tsbuildinfo",
|
|
39
39
|
"clear:deps": "rm -rf ./node_modules && rm -rf ./dist"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "4ea55d84a33098abf2830f86bb94ba44f7ee0c20",
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"@rnw-community/shared": "^0.49.0",
|
|
44
44
|
"rxjs": "^7.4.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@rnw-community/shared": "^0.
|
|
47
|
+
"@rnw-community/shared": "^0.53.0",
|
|
48
48
|
"expect-type": "^0.13.0",
|
|
49
49
|
"rxjs": "^7.4.0"
|
|
50
50
|
}
|
package/readme.md
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
# RxJS error utils
|
|
2
2
|
|
|
3
|
-
Utils that help work with errors in rxjs observable's
|
|
3
|
+
Utils that help work with errors in rxjs observable's.
|
|
4
|
+
|
|
5
|
+
[](https://badge.fury.io/js/%40rnw-community%2Frxjs-errors)
|
|
6
|
+
[](https://www.npmjs.com/package/%40rnw-community%2Frxjs-errors)
|
|
4
7
|
|
|
5
8
|
## Classes
|
|
6
9
|
|
|
7
|
-
-
|
|
10
|
+
- `RxJSFilterError` - custom error used by error operators.
|
|
8
11
|
|
|
9
12
|
## Available operators
|
|
10
13
|
|
|
11
|
-
-
|
|
12
|
-
|
|
14
|
+
- [`filterWithException`](#filterwithexception) - works like `filter` from rxjs, but throw an error instead of ignoring the
|
|
15
|
+
value.
|
|
13
16
|
|
|
14
|
-
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
- [`rethrowException`](#rethrowexception) - will catch any error in the observable, create a
|
|
18
|
+
new `RxJSFilterError` (or any custom) with custom message and log it with a custom logger function that you can optionally
|
|
19
|
+
pass in. If it catches `RxJSFilterError` (or any custom), it will
|
|
20
|
+
just rethrow that exception as is.
|
|
18
21
|
|
|
19
22
|
## Usage examples
|
|
20
23
|
|
|
@@ -27,7 +30,12 @@ import { of } from 'rxjs';
|
|
|
27
30
|
import { filterWithException } from '@rnw-community/rxjs-errors';
|
|
28
31
|
|
|
29
32
|
of('C')
|
|
30
|
-
.pipe(
|
|
33
|
+
.pipe(
|
|
34
|
+
filterWithException(
|
|
35
|
+
letter => letter === 'A',
|
|
36
|
+
letter => `Wanted A, but got ${letter}`
|
|
37
|
+
)
|
|
38
|
+
)
|
|
31
39
|
.subscribe(value => console.log(value));
|
|
32
40
|
```
|
|
33
41
|
|
|
@@ -39,7 +47,13 @@ import { BadRequestException } from '@nestjs/common';
|
|
|
39
47
|
import { of } from 'rxjs';
|
|
40
48
|
|
|
41
49
|
of('F')
|
|
42
|
-
.pipe(
|
|
50
|
+
.pipe(
|
|
51
|
+
filterWithException(
|
|
52
|
+
letter => letter === 'A',
|
|
53
|
+
letter => `Wanted A, but got ${letter}`,
|
|
54
|
+
BadRequestException
|
|
55
|
+
)
|
|
56
|
+
)
|
|
43
57
|
.subscribe(value => console.log(value));
|
|
44
58
|
```
|
|
45
59
|
|
|
@@ -55,7 +69,7 @@ const isString = (val: unknown): val is string => typeof val === 'string';
|
|
|
55
69
|
|
|
56
70
|
of(value) // `unknown` here
|
|
57
71
|
.pipe(filterWithException(isString, value => `Wanted string, but got ${typeof value}`))
|
|
58
|
-
.subscribe(value /* `string` here */ => {
|
|
72
|
+
.subscribe((value) /* `string` here */ => {
|
|
59
73
|
console.log(value);
|
|
60
74
|
});
|
|
61
75
|
```
|
|
@@ -84,39 +98,36 @@ import { filterWithException, rethrowException } from '@rnw-community/rxjs-error
|
|
|
84
98
|
import { of } from 'rxjs';
|
|
85
99
|
|
|
86
100
|
class LetterService {
|
|
87
|
-
constructor(private readonly repository: ILetterRepository) {
|
|
88
|
-
}
|
|
101
|
+
constructor(private readonly repository: ILetterRepository) {}
|
|
89
102
|
|
|
90
103
|
checkLetter$(letter: string): Observable<string> {
|
|
91
104
|
return of(letter).pipe(
|
|
92
|
-
filterWithException(letter !== 'A',
|
|
105
|
+
filterWithException(letter !== 'A', 'Invalid character'),
|
|
93
106
|
concatMap(letter => this.repository.doSomething(letter)),
|
|
94
107
|
rethrowException('Could not check letter', console.error)
|
|
95
|
-
)
|
|
108
|
+
);
|
|
96
109
|
}
|
|
97
110
|
}
|
|
98
111
|
```
|
|
99
112
|
|
|
100
|
-
In this example any error except for `LetterError` will be caught, logged and a `LetterError` will be thrown with a
|
|
113
|
+
In this example any error except for `LetterError` will be caught, logged and a `LetterError` will be thrown with a "Could
|
|
101
114
|
not check letter" message.
|
|
102
115
|
|
|
103
116
|
```typescript
|
|
104
117
|
import { filterWithException, rethrowException } from '@rnw-community/rxjs-errors/src';
|
|
105
118
|
import { of } from 'rxjs';
|
|
106
119
|
|
|
107
|
-
class LetterError extends Error {
|
|
108
|
-
}
|
|
120
|
+
class LetterError extends Error {}
|
|
109
121
|
|
|
110
122
|
class LetterService {
|
|
111
|
-
constructor(private readonly repository: ILetterRepository) {
|
|
112
|
-
}
|
|
123
|
+
constructor(private readonly repository: ILetterRepository) {}
|
|
113
124
|
|
|
114
125
|
checkLetter$(letter: string): Observable<string> {
|
|
115
126
|
return of(letter).pipe(
|
|
116
|
-
filterWithException(letter !== 'A',
|
|
127
|
+
filterWithException(letter !== 'A', 'Invalid character'),
|
|
117
128
|
concatMap(letter => this.repository.doSomething(letter)),
|
|
118
129
|
rethrowException('Could not check letter', console.error, LetterError)
|
|
119
|
-
)
|
|
130
|
+
);
|
|
120
131
|
}
|
|
121
132
|
}
|
|
122
133
|
```
|
|
@@ -129,15 +140,14 @@ import { getErrorMessage } from '@rnw-community/shared';
|
|
|
129
140
|
import { of } from 'rxjs';
|
|
130
141
|
|
|
131
142
|
class LetterService {
|
|
132
|
-
constructor(private readonly repository: ILetterRepository) {
|
|
133
|
-
}
|
|
143
|
+
constructor(private readonly repository: ILetterRepository) {}
|
|
134
144
|
|
|
135
145
|
checkLetter$(letter: string): Observable<string> {
|
|
136
146
|
return of(letter).pipe(
|
|
137
|
-
filterWithException(letter !== 'A',
|
|
147
|
+
filterWithException(letter !== 'A', 'Invalid character'),
|
|
138
148
|
concatMap(letter => this.repository.doSomething(letter)),
|
|
139
149
|
rethrowException((err: unknown) => getErrorMessage(err), console.error)
|
|
140
|
-
)
|
|
150
|
+
);
|
|
141
151
|
}
|
|
142
152
|
}
|
|
143
153
|
```
|
|
@@ -150,15 +160,14 @@ import { getErrorMessage } from '@rnw-community/shared';
|
|
|
150
160
|
import { of } from 'rxjs';
|
|
151
161
|
|
|
152
162
|
class LetterService {
|
|
153
|
-
constructor(private readonly repository: ILetterRepository) {
|
|
154
|
-
}
|
|
163
|
+
constructor(private readonly repository: ILetterRepository) {}
|
|
155
164
|
|
|
156
165
|
checkLetter$(letter: string): Observable<string> {
|
|
157
166
|
return of(letter).pipe(
|
|
158
|
-
filterWithException(letter !== 'A',
|
|
167
|
+
filterWithException(letter !== 'A', 'Invalid character'),
|
|
159
168
|
concatMap(letter => this.repository.doSomething(letter)),
|
|
160
169
|
rethrowException('Could not check letter')
|
|
161
|
-
)
|
|
170
|
+
);
|
|
162
171
|
}
|
|
163
172
|
}
|
|
164
173
|
```
|