private static async Task HandleStatusCodeException(HttpContext context, ApiException ex) { context.Response.ContentType = "application/json"; context.Response.StatusCode = (int)ex.StatusCode; await context.Response.WriteAsync(ex.ToJson()); }