1. How do you handle exception in webapi and what is the pattern used ?
Example for Generic respose, I have mentioned here.
public record Response<T> : ResponseBase
{
[JsonProperty(PropertyName = "data", Order = 5)]
public T Data { get; set; }
[JsonProperty(PropertyName = "recordsCount", Order = 4)]
public int RecordsCount { get; set; }
[JsonProperty(PropertyName = "message")]
public string Message { get; set; }
}
public record ResponseBase
{
[JsonProperty(PropertyName = "errorMessage", Order = 3)]
public string ErrorMessage { get; set; }
[JsonProperty(PropertyName = "isSuccess", Order = 1)]
public virtual bool IsSuccess { get; set; } = true;
[JsonProperty(PropertyName = "reasonPhrase", Order = 4)]
public string ReasonPhrase { get; set; } = "OK";
[JsonProperty(PropertyName = "statusCode", Order = 2)]
public HttpStatusCode StatusCode { get; set; } = HttpStatusCode.OK;
}
No comments:
Post a Comment