private static string SnakeCaseErrorCode(DomainErrorCode code) { return(String.Concat( code.ToString().Select( (c, i) => i > 0 && Char.IsUpper(c) ? ("_" + c.ToString()) : c.ToString() ) ).ToLower()); }
private static async Task WriteJsonError( HttpContext context, HttpStatusCode statusCode, DomainErrorCode errorCode, string reasonPhrase, string errorMessage) { context.Response.ContentType = "application/json"; context.Response.StatusCode = (int)statusCode; context.Response.HttpContext.Features.Get <IHttpResponseFeature>().ReasonPhrase = reasonPhrase; var response = new Dictionary <string, object> { { "ErrorCode", (int)errorCode }, { "ErrorMessage", errorMessage }, }; var jsonBody = JsonConvert.SerializeObject(response); context.Response.ContentLength = Encoding.UTF8.GetByteCount(jsonBody); await context.Response.WriteAsync(jsonBody); }
public DomainError(DomainErrorCode errorCode, string errorMessage) { ErrorCode = errorCode; ErrorMessage = errorMessage; }
public DomainException(DomainErrorCode code, string message) : base(message) { ErrorCode = code; }
public DomainException(DomainErrorCode code, string message, Exception innerException) : base(message, innerException) { ErrorCode = code; }