This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Net.Http; | |
using System.Net.Http.Json; | |
using System.Threading.Tasks; | |
namespace ConsoleApp1 | |
{ | |
class Program | |
{ | |
static async Task Main(string[] args) | |
{ | |
var httpClient = new HttpClient(new ProblemDetailsHttpMessageHandler()); | |
try | |
{ | |
var result = await httpClient.PostAsJsonAsync("https://localhost:5001/Demo", new {}); | |
} | |
catch (ProblemDetailsException problemDetailsException) | |
{ | |
Console.WriteLine($"Title: {problemDetailsException.Details.Title}"); | |
Console.WriteLine($"Detail: {problemDetailsException.Details.Detail}"); | |
Console.WriteLine($"Instance: {problemDetailsException.Details.Instance}"); | |
Console.WriteLine($"Type: {problemDetailsException.Details.Type}"); | |
Console.WriteLine($"Status: {problemDetailsException.Details.Status}"); | |
if (problemDetailsException.Details.Type == "https://example.net/validation-error") | |
{ | |
Console.WriteLine($"Validation Errors:"); | |
var validationErrors = problemDetailsException.Details.ToValidationProblemDetails(); | |
foreach (var invalidParam in validationErrors.InvalidParams) | |
{ | |
Console.WriteLine($"{invalidParam.Name} - {invalidParam.Reason}"); | |
} | |
} | |
Console.ReadKey(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment