Last active
May 28, 2020 09:24
-
-
Save rithala/6f92d5712e7016026b268e1f803443f3 to your computer and use it in GitHub Desktop.
REST Response Class
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
namespace YourNamespace | |
{ | |
public abstract class BaseResponse | |
{ | |
public bool IsError { get; } | |
protected BaseResponse(bool isError) | |
{ | |
IsError = isError; | |
} | |
} | |
public class ErrorResponse : BaseResponse | |
{ | |
public string ErrorMessage { get; } | |
public string ErrorStackTrace { get; } | |
public ErrorResponse InnerError { get; } | |
public ErrorResponse(Exception exception) : base(true) | |
{ | |
ErrorMessage = exception.Message; | |
ErrorStackTrace = exception.StackTrace; | |
if (exception.InnerException != null) | |
{ | |
InnerError = new ErrorResponse(exception.InnerException); | |
} | |
} | |
} | |
public class DataResponse<T> : BaseResponse | |
{ | |
public T Data { get; } | |
public DataResponse(T data) : base(false) | |
{ | |
Data = data; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment