I am trying to handle response that is different from what I expect normally. Normally I would expect a response that looks like the Item model below:
public class Item
{
public string Response { get; set; }
public string StatusCode { get; set; }
}
But if the DB is down or not responding, it returns this type of answer as seen from the DbError model below:
public class DbError
{
public string Code { get; set; }
public string Title { get; set; }
public string Message { get; set; }
public string ErrorCode { get; set; }
public string Cause { get; set; }
}
Typically I would try to serialize the response like this:
Item? response = JsonSerializer.Deserialize<Item>(jsonString);
How can I try to serialize as an Item but in case that the db is returning the error, serialize with the DbError model?