Click here to Skip to main content
14,335,764 members

Web Development

 
QuestionASP.Net Web API Deployment Not Working Pin
Kevin Marois29-May-19 6:56
professionalKevin Marois29-May-19 6:56 
AnswerRe: ASP.Net Web API Deployment Not Working Pin
Richard Deeming29-May-19 7:21
mveRichard Deeming29-May-19 7:21 
GeneralRe: ASP.Net Web API Deployment Not Working Pin
Kevin Marois29-May-19 7:42
professionalKevin Marois29-May-19 7:42 
GeneralRe: ASP.Net Web API Deployment Not Working Pin
Richard Deeming29-May-19 7:53
mveRichard Deeming29-May-19 7:53 
GeneralRe: ASP.Net Web API Deployment Not Working Pin
Kevin Marois29-May-19 8:12
professionalKevin Marois29-May-19 8:12 
QuestionPhoto Collage in Bootstrap...possible? Pin
Member 1208020129-May-19 6:05
memberMember 1208020129-May-19 6:05 
AnswerRe: Photo Collage in Bootstrap...possible? Pin
Pete O'Hanlon29-May-19 22:04
protectorPete O'Hanlon29-May-19 22:04 
QuestionHandling Web Request Failures Pin
Kevin Marois22-May-19 5:28
professionalKevin Marois22-May-19 5:28 
I have a RestSharp wrapprer class to work with my WebAPI, and it has an Execute method looks like this
public async Task<T> ExecuteAsync<T>() where T : new()
{
    URL = client.BaseUrl + request.Resource;

    IRestResponse<T> restResponse = await client.ExecuteTaskAsync<T>(request, new CancellationToken());

    var result = (T)restResponse.Data;

    if (!string.IsNullOrEmpty(restResponse.ErrorMessage))
    {
        throw new Exception(restResponse.ErrorMessage);
    }
    else
    {
        if ((int)restResponse.StatusCode >= 299)
        {
            string message = string.Format("An error occured calling the WebAPI. {0} The status code is '{1}'. {2} The error message is {3}",
                                            Environment.NewLine, restResponse.StatusCode, Environment.NewLine, restResponse.Content);
            throw new Exception(message);
        }
    }

    return result;
}
I then use a proxy class like this. This class has all the calls to the api in it
public async Task<List<OperatorEntity>> GetAllOperatorsAsync()
{
    var webAPIExecutor = new WebAPIExecutor(Credentials, ServerUrl, "/Operator/GetAllOperators/", Method.GET);
    return await webAPIExecutor.ExecuteAsync<List<OperatorEntity>>();
}
All of my web calls are contained in this proxy. I then use it like this:
private async void GetAllOperators()
{
    var operators = await APIProxy.GetAllOperatorsAsync();

    LoadOperatorList(operators);
}
The question is, what is the right way to handle a failure? For example, the server is down, or the credentials are incorrect? Or an exception happened on the server side?

You can see that I have some exception handling in the ExecuteAsync method, but it this the right way to handle this?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.

AnswerRe: Handling Web Request Failures Pin
Nathan Minier22-May-19 6:02
professionalNathan Minier22-May-19 6:02 
QuestionRestSharp Response Question Pin
Kevin Marois20-May-19 13:30
professionalKevin Marois20-May-19 13:30 
AnswerRe: RestSharp Response Question Pin
Richard Deeming21-May-19 0:49
mveRichard Deeming21-May-19 0:49 
QuestionAuthentication/Authorisation Pin
Mycroft Holmes16-May-19 12:47
memberMycroft Holmes16-May-19 12:47 
AnswerRe: Authentication/Authorisation Pin
Richard Deeming17-May-19 1:03
mveRichard Deeming17-May-19 1:03 
GeneralRe: Authentication/Authorisation Pin
Mycroft Holmes17-May-19 12:44
memberMycroft Holmes17-May-19 12:44 
QuestionQuestion about empty button top positioning. Pin
neodeaths11-May-19 12:39
memberneodeaths11-May-19 12:39 
AnswerRe: Question about empty button top positioning. Pin
Richard Deeming13-May-19 8:09
mveRichard Deeming13-May-19 8:09 
QuestionWeb API Not Working Pin
Kevin Marois10-May-19 10:57
professionalKevin Marois10-May-19 10:57 
AnswerRe: Web API Not Working Pin
Richard Deeming10-May-19 11:12
mveRichard Deeming10-May-19 11:12 
GeneralMessage Closed Pin
16-May-19 23:01
memberavrora malkova16-May-19 23:01 
QuestionNeed Some Of Your Help Pin
Member 143595087-May-19 21:12
memberMember 143595087-May-19 21:12 
QuestionMVC5 Load partial view on link click Pin
#realJSOP4-May-19 6:52
mve#realJSOP4-May-19 6:52 
AnswerRe: MVC5 Load partial view on link click Pin
jkirkerx5-May-19 13:53
professionaljkirkerx5-May-19 13:53 
GeneralRe: MVC5 Load partial view on link click Pin
#realJSOP6-May-19 1:38
mve#realJSOP6-May-19 1:38 
GeneralMessage Closed Pin
14-May-19 8:43
membermalkovich198814-May-19 8:43 
AnswerRe: MVC5 Load partial view on link click Pin
Richard Deeming8-May-19 1:31
mveRichard Deeming8-May-19 1:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.