private async Task WriteExceptionAsync(HttpContext context, Exception exception) { var response = context.Response; response.StatusCode = (int)HttpStatusCode.OK; response.ContentType = "application/json"; await response.WriteAsync(JsonConvert.SerializeObject(DkmsResult.Failure(message: exception.Message))).ConfigureAwait(false); }
public override void OnResultExecuting(ResultExecutingContext context) { if (context.Result is ObjectResult) { var objectResult = context.Result as ObjectResult; if (objectResult.Value == null) { SetResponse(context, DkmsResult.Success(string.Empty)); } else { SetResponse(context, DkmsResult.Success(objectResult.Value)); } } else if (context.Result is EmptyResult) { SetResponse(context, DkmsResult.Success(string.Empty)); } else if (context.Result is ContentResult) { SetResponse(context, DkmsResult.Success((context.Result as ContentResult).Content)); } }
private void SetResponse(ResultExecutingContext context, DkmsResult result) { context.Result = new ObjectResult(result); }