我希望能够在调用class C(object):
__slots__ = 'i'
def __init__(self, i):
self.i = i
def __getstate__(self):
return { slot: getattr(self, slot) for slot in C.__slots__ }
def __setstate__(self, d):
for slot in d:
setattr(self, slot, d[slot])
class D(C):
__slots__ = 'j'
def __init__(self, i, j):
super(D, self).__init__(i)
self.j = j
def __getstate__(self):
return (
C.__getstate__(self),
{ slot: getattr(self, slot) for slot in self.__slots__ }
)
def __setstate__(self, ds):
C.__setstate__(self, ds[0])
d = ds[1]
for slot in d:
setattr(self, slot, d[slot])
d = pickle.loads(pickle.dumps(D(1, 2), -1))
assert d.i == 1
assert d.j == 2
时处理任何错误。可以在switchmap块中处理错误,或者在这种情况下如何处理错误?
__getstate__
答案 0 :(得分:18)
使用catchError方法
this.authService.refreshToken()
.pipe(
switchMap(() => {...}),
catchError((e) => {
// handle e and return a safe value or re-throw
if (isCritical(e)) {
return throwError(e);
}
return of([]);
})
);