本文整理汇总了TypeScript中rxjs.Observer.error方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Observer.error方法的具体用法?TypeScript Observer.error怎么用?TypeScript Observer.error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rxjs.Observer
的用法示例。
在下文中一共展示了Observer.error方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Error
return Observable.create((observer: Observer<any>) => {
if (!patch || !patch.name) {
return observer.error(new Error('User name is required'))
}
Observable.fromPromise(userFetch.update(patch))
.concatMap(x => UserModel.update(x))
.forEach(result => observer.next(result))
})
示例2:
const onComplete = () => {
if (savedError !== null) {
observer.error(savedError);
} else {
observer.next(savedResult);
observer.complete();
}
};
示例3: return
return ({ err, response, isDisposed }: WritePacket) => {
if (err) {
return observer.error(err);
} else if (isDisposed) {
return observer.complete();
}
observer.next(response);
};
示例4: handleInvalidWorkstation
handleInvalidWorkstation(path: string): void {
if (path.startsWith(WS_MANAGE_PATH)) {
// user is navigating to the WS admin page.
this.observer.complete();
} else {
this.router.navigate([WS_MANAGE_PATH]);
this.observer.error(`Auth session linked to no
workstation or a workstation unknown to this browser`);
}
}
示例5: catch
.then((data) => {
try {
const json = JSON.parse(data);
observer.next(successResponse(url, json, 200));
observer.complete();
} catch (error) {
// Even though the response status was 2xx, this is still an error.
// The parse error contains the text of the body that failed to parse.
const errorResult = { error, text: data };
observer.error(errorResponse(url, errorResult, 200));
}
}, (err: Object) => {
示例6:
return new Observable<any>((responseObserver: Observer<any>) => {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
(position) => {
responseObserver.next(position);
responseObserver.complete();
},
(evt) => responseObserver.error(evt),
geoLocationOptions
);
} else {
responseObserver.error('Browser Geolocation service failed.');
}
});
示例7:
newRef.set(value, (err: Error) => {
if (err) {
observer.error({
type: `CREATE_FAILED_IN_${PREFIX}`,
payload: {
originalPayload: value,
error: err,
}
});
} else {
observer.next({
type: `CREATED_IN_${PREFIX}`,
payload: Object.assign({}, value, { firebaseKey: newRef.key() })
});
}
});
示例8: fn
return Observable.create((observer: Observer<any>) => {
try {
if (!called) {
called = true;
fn()
.then((_record: any) => {
record = _record;
observer.next(record);
observer.complete();
})
.catch((err: any) => observer.error(err));
} else if (record) {
observer.next(record);
observer.complete();
}
} catch (err) {
observer.error(err);
}
});
示例9: Observable
return new Observable((observer: Observer<T>) => {
if (nsFileSystem.fileExists(url)) {
const localFile = nsFileSystem.fileFromPath(url);
localFile.readText()
.then((data) => {
try {
const json = JSON.parse(data);
observer.next(successResponse(url, json, 200));
observer.complete();
} catch (error) {
// Even though the response status was 2xx, this is still an error.
// The parse error contains the text of the body that failed to parse.
const errorResult = { error, text: data };
observer.error(errorResponse(url, errorResult, 200));
}
}, (err: Object) => {
observer.error(errorResponse(url, err, 400));
});
} else {
observer.error(errorResponse(url, "Not Found", 404));
}
});