本文整理匯總了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
});
}