public ApiResponse(int statusCode, string message = "", object result = null, ApiError apiError = null)
 {
     StatusCode        = statusCode;
     Message           = message;
     Result            = result;
     ResponseException = apiError;
 }
Example #2
0
        private Task HandleRequestAsync(HttpContext context, object body, ResponseMessage message, ApiError apiError = null)
        {
            var code = context.Response.StatusCode;

            context.Response.ContentType = "application/json";

            var bodyText = string.Empty;

            if (body != null)
            {
                bodyText = !body.ToString().IsValidJson() ? JsonConvert.SerializeObject(body) : body.ToString();
            }

            var bodyContent = JsonConvert.DeserializeObject <dynamic>(bodyText);
            var apiResponse = new ApiResponse(code, message.GetDescription(), bodyContent, apiError);
            var jsonString  = JsonConvert.SerializeObject(apiResponse);

            context.Response.Body.SetLength(0L);
            return(context.Response.WriteAsync(jsonString));
        }