本文整理汇总了TypeScript中rxjs/observable/throw._throw函数的典型用法代码示例。如果您正苦于以下问题:TypeScript _throw函数的具体用法?TypeScript _throw怎么用?TypeScript _throw使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_throw函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: concat
(() => {
try {
concat(of(1), _throw('Something went wrong')).subscribe(n => console.log(n));
} catch (ex) {
console.error(ex);
}
}); //();
示例2: errorHandler
// Customize the default error handler here if needed
private errorHandler(response: Response): Observable<Response> {
if (environment.production) {
// Avoid unchaught exceptions on production
log.error('Request error', response);
return _throw(response);
}
throw response;
}
示例3: login
login({ username, password }: Authenticate) {
/**
* Simulate a failed login to display the error
* message for the login form.
*/
if (username !== 'test') {
return _throw('Invalid username or password');
}
return of({ name: 'User' });
}
示例4: CancelGeneratePreview
return next.handle(apiReq).catch((err: HttpErrorResponse) => {
if (err.status === 0 || err.status === 500) {
// An error we can't help with happened, one of:
// 1. Network error
// 2. Client side JS error
// 3. Server side 500 error
this.store.dispatch(new CancelGeneratePreview());
this.snackBar.open('Sorry, something went wrong!', '', {duration: 5000});
return Observable.empty();
}
return _throw(err.error);
});
示例5: handleError
handleError(err: HttpResponse<any>): Observable<any> {
return _throw(err);
}
示例6: _throw
get: url => _throw('TESTING ERROR')
示例7: catchError
catchError((error, retry) => _throw(this.getErrorResponse(error)))
示例8: _throw
.pipe(catchError(err => _throw(err)));
示例9: ObservableThrow
uploadForm(event): Observable<any> {
// console.log("uplodaForm");
if (event === void 0 || event.target === void 0 || event.target.files === void 0) {
return ObservableThrow(new Error('file_is_not_selected'));
}
const files = event.target.files;
if (files === void 0 || files[0] === void 0 || !files[0]) {
return ObservableThrow(new Error('file_is_not_selected_or_file_does_not_exist'));
}
const file = files[0];
const formData = new FormData();
formData.append('userfile', file, file.name);
formData.append('route', 'file.upload');
formData.append('session_id', this.user.sessionId);
// console.log("url: ", this.x.getServerUrl());
// console.log("data: ", formData);
const req = new HttpRequest('POST', this.x.getServerUrl(), formData, {
reportProgress: true,
responseType: 'json'
});
return this.http.request(req)
.map(e => {
if (e instanceof HttpResponse) { // success event.
if ( e.status === 200 ) {
if ( e.body && e.body['code'] === 0) {
return e.body['data'];
} else {
return e.body; // Return Wordpress Xapi Server error
}
}
} else if ( e instanceof HttpHeaderResponse ) { // header event
return {};
} else if (e.type === HttpEventType.UploadProgress) { // progress event
return Math.round(100 * e.loaded / e.total);
}
return e; // other events
});
}