Skip to content

Error Handling

Handle API errors gracefully using the ApiException type.

This example assumes using HuggingFace; is in scope and apiKey contains your HuggingFace API key.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
using var client = new HuggingFaceClient("invalid-api-key");

try
{
    await client.Auth.GetWhoamiV2Async();
}
catch (ApiException ex)
{
    Console.WriteLine($"Status: {ex.StatusCode}");
    Console.WriteLine($"Message: {ex.Message}");
    Console.WriteLine($"Body: {ex.ResponseBody}");

}