You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.1 KiB
37 lines
1.1 KiB
|
|
using Microsoft.AspNetCore.Http;
|
|
using System.Net;
|
|
|
|
namespace DealerSelection.Common.Logging;
|
|
|
|
public class ResponseInfo
|
|
{
|
|
public ResponseInfo(HttpResponse response)
|
|
{
|
|
StatusCode = (HttpStatusCode)response.StatusCode;
|
|
|
|
if (IsSuccessStatusCode)
|
|
IsSuccess = true;
|
|
else if (StatusCode >= HttpStatusCode.InternalServerError)
|
|
IsSuccess = false;
|
|
else
|
|
IsSuccess = null;
|
|
|
|
TimeStamp = DateTime.Now;
|
|
}
|
|
|
|
public bool IsSuccessStatusCode => (int)StatusCode >= 200 && (int)StatusCode <= 299;
|
|
public bool? IsSuccess { get; }
|
|
public HttpStatusCode StatusCode { get; }
|
|
public DateTime TimeStamp { get; }
|
|
public string? ContentBody { get; set; }
|
|
public string? ContentType { get; set; }
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"{nameof(StatusCode)}: {StatusCode}, " +
|
|
$"{nameof(TimeStamp)}: {TimeStamp}, " +
|
|
$"{nameof(ContentType)}: {ContentType} "
|
|
+ (string.IsNullOrWhiteSpace(ContentBody)? null : $", {nameof(ContentBody)}: {ContentBody} ");
|
|
}
|
|
}
|