java中调用feign client api异常时如何继续程序
how to continue the program when there is exception while calling feign client api in java
public string prospect(List<ProspectRequest> prospectRequest, String primaryClientId) {
if(p2p(primaryClientId)=="Success") {
for(ProspectRequest prospect : prospectRequest) {
p2p(prospect.getId());
}
// rest of code i would like to continue
}
}
public string p2p(String id){
crmApi.getProspectId(id);//this is external client api
String message = "Success";
return message;
}
如果 p2p(primaryClientId) 失败,那么我需要停止整个过程。我想如何继续“我想继续的其余代码”。
如果伪装客户端 api crmApi.getProspectId 成功,则返回成功消息,这是一个很好的例子。
如果 crmApi.getProspectId api 给出错误,那么我仍然需要为下一组客户端继续 p2p() 程序。这是如何工作的。
提前致谢。
看来你只需要使用 try catch finally 块
public string prospect(List<ProspectRequest> prospectRequest, String primaryClientId) {
try {
if(p2p(primaryClientId)=="Success") {
for(ProspectRequest prospect : prospectRequest) {
p2p(prospect.getId());
}
} catch (RuntimeException e) {} // Exception can be specified exp. RuntimeException
finally {
// rest of code i would like to continue
}
}
}
public string p2p(String id){
crmApi.getProspectId(id);//this is external client api
String message = "Success";
return message;
}
如果您需要第一个 if 块中的某些内容,您可以在 catch 块中放置一个选项(如果 if 块失败)。当
if(p2p(primaryClientId)=="Success") {
for(ProspectRequest prospect : prospectRequest) {
p2p(prospect.getId());
}
抛出检查异常需要将 RuntimeExpection 更改为超类 Exception
已编辑:
for(ProspectRequest prospect : prospectRequest) {
try {
p2p(prospect.getId());
} 赶上(RuntimeExpection e){}
}
public string prospect(List<ProspectRequest> prospectRequest, String primaryClientId) {
if(p2p(primaryClientId)=="Success") {
for(ProspectRequest prospect : prospectRequest) {
p2p(prospect.getId());
}
// rest of code i would like to continue
}
}
public string p2p(String id){
crmApi.getProspectId(id);//this is external client api
String message = "Success";
return message;
}
如果 p2p(primaryClientId) 失败,那么我需要停止整个过程。我想如何继续“我想继续的其余代码”。
如果伪装客户端 api crmApi.getProspectId 成功,则返回成功消息,这是一个很好的例子。 如果 crmApi.getProspectId api 给出错误,那么我仍然需要为下一组客户端继续 p2p() 程序。这是如何工作的。
提前致谢。
看来你只需要使用 try catch finally 块
public string prospect(List<ProspectRequest> prospectRequest, String primaryClientId) {
try {
if(p2p(primaryClientId)=="Success") {
for(ProspectRequest prospect : prospectRequest) {
p2p(prospect.getId());
}
} catch (RuntimeException e) {} // Exception can be specified exp. RuntimeException
finally {
// rest of code i would like to continue
}
}
}
public string p2p(String id){
crmApi.getProspectId(id);//this is external client api
String message = "Success";
return message;
}
如果您需要第一个 if 块中的某些内容,您可以在 catch 块中放置一个选项(如果 if 块失败)。当
if(p2p(primaryClientId)=="Success") {
for(ProspectRequest prospect : prospectRequest) {
p2p(prospect.getId());
}
抛出检查异常需要将 RuntimeExpection 更改为超类 Exception
已编辑:
for(ProspectRequest prospect : prospectRequest) {
try {
p2p(prospect.getId());
} 赶上(RuntimeExpection e){} }