[英]Reject Promise in Resolve as a Service
When i reject a promise in resolve ,this error will be shown on console. 当我拒绝承诺时,此错误将显示在控制台上。 IN CONSOLE: EXCEPTION: Uncaught (in promise): null error_handler.js:56 ORIGINAL STACKTRACE: Error: Uncaught (in promise): null
在控制台中:异常:未捕获(在承诺中):null error_handler.js:56 ORIGINAL STACKTRACE:错误:未捕获(在承诺中):null
@Injectable()
export class PaymentScheduleResolve implements Resolve<any> {
constructor(private rtoService: RtoService,
private rtoActivationService: RtoActivationService,
private router:Router,
private toastr: Toastr) {
}
resolve() {
var self = this;
return new Promise((resolve, reject) => {
let rtoInfo = self.rtoActivationService.getRtoInfo();
if (!rtoInfo) {
reject("null");// This will produce error on console
}
else{
self.rtoActivationService.getPaymentSchedules(rtoInfo.Id, rtoInfo.Data.RtoRentLength)
.then((res: any) => {
if (res.Response && res.Response.Code === 200) {
resolve(res.Response.Data);
}
else {
reject(null);// This will produce error on console
}
})
.catch((err: any) => {
console.log(err);
reject(null);// This will produce error on console
})
}
});
}
Just use 只是用
resolve(null);
instead of 代替
reject(null);
Use the following to reject the Resolver. 使用以下命令拒绝解析器。 This will redirect you to the default route.
这会将您重定向到默认路由。
reject({message: err , ngNavigationCancelingError: true});
Or you can redirect to the error page 或者您可以重定向到错误页面
this.router.navigateByUrl('errorPage');
resolve(false);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.