Handling return value from Web Service Call Wrapper
Posted
by coffeeaddict
on Stack Overflow
See other posts from Stack Overflow
or by coffeeaddict
Published on 2010-06-15T20:21:10Z
Indexed on
2010/06/15
20:22 UTC
Read the original article
Hit count: 148
c#
I created this method below which makes an HTTP call to a 3rd party API. I just want opinions on if I'm handling this the best way. If the call fails, I need to return the ExistsInList bool value only if the response is not null. But in the last return statement, wouldn't I have to essentially do another return selectResponse == null ? false : selectResponse.ExistsInList; to check for null first just like the previous return in the catch?
Just seems redundant the way I'm approaching this and I don't know if I really need to check for null again in the final return but I figure yes, because you can't always rely on the response to give you a valid response even if there were no errors picked up.
public static bool UserExistsInList(string email, string listID)
{
SelectRecipientRequest selectRequest = new SelectRecipientRequest(email, listID);
SelectRecipientResponse selectResponse = null;
try
{
selectResponse = (SelectRecipientResponse)selectRequest.SendRequest();
}
catch (Exception)
{
return selectResponse == null ? false : selectResponse.ExistsInList;
}
return selectResponse.ExistsInList;
}
© Stack Overflow or respective owner