Skip to content

Instantly share code, notes, and snippets.

@rithala
Last active May 28, 2020 09:24
Show Gist options
  • Save rithala/6f92d5712e7016026b268e1f803443f3 to your computer and use it in GitHub Desktop.
Save rithala/6f92d5712e7016026b268e1f803443f3 to your computer and use it in GitHub Desktop.
REST Response Class
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