What is the name of the pattern where a method returns an object with properties for status, failure messages, and the desired data (as opposed to raising exceptions)?
As an example, RestSharp uses this pattern:
var response = client.Execute<T>(request);
// incomplete example - you'd want to check more here
if (response.ErrorException == null) return response.Data;
public abstract class RestResponseBase
{
/// <summary>
/// Status of the request. Will return Error for transport errors.
/// HTTP errors will still return ResponseStatus.Completed, check StatusCode instead
/// </summary>
public ResponseStatus ResponseStatus { get; set; }
public HttpStatusCode StatusCode { get; set; }
public string ErrorMessage { get; set; }
public Exception ErrorException { get; set; }
// ...
}
public class RestResponse<T> : RestResponseBase, IRestResponse<T>
{
public T Data { get; set; }
// ...
}
Aucun commentaire:
Enregistrer un commentaire