Skip to content

Latest commit

 

History

History
37 lines (36 loc) · 864 Bytes

clients-error.md

File metadata and controls

37 lines (36 loc) · 864 Bytes

Error Handling

When errors are encountered while executing client operations, they are surfaced with an HttpOperationException. The exception includes the HTTP Request and Response objects as shown in this example:

try
{
    pets = client.FindPets(null, -1);
}
catch (HttpOperationException ex)
{
    var request = ex.Request;
    var response = ex.Response;
}

Many services define models for error conditions. Use either the base type RestException or a model type to catch the exception:

try
{
    pets = client.FindPets(null, -1);
}
catch (RestException ex)
{
    var request = ex.Request;
    var response = ex.Response;
}

try
{
    pets = client.FindPets(null, -1);
}
catch (PetException ex)
{
    var request = ex.Request;
    var response = ex.Response;
    var errorData = ex.Body;
    var message = errorData.Message;
}