我想在函数失败时发送return Error,但是我不知道该怎么做...
Service.ts
math(){
try {
.
.
.
} catch (error) {
return "error";
}
}
calc(url){
num = math();
if (num !== "error"){
return this.http.get<Object[]>(url);
} else {
return Error;
}
}
component.ts
this.service.calc(url).subscribe(
data => {
this.params = data;
}, error => {
this.errorServer = true;
this.myMessage.message = "Error";
}
);
我在this.service.calc(url).subscribe
中遇到错误,因为这不允许-> Return Error
从calc
答案 0 :(得分:2)
使用from collections import OrderedDict
def ordered_to_regular_dict(d):
if isinstance(d, OrderedDict) or isinstance(d, dict):
d = {k: ordered_to_regular_dict(v) for k, v in d.items()}
elif isinstance(d, list):
d = [ordered_to_regular_dict(v) for v in d.items()]
elif isinstance(d, tuple):
d = (ordered_to_regular_dict(v) for v in d.items())
return d
获得可观察到的回报。
throwError