private void ReleaseContext(ServerActionContext context) { if (_contexts.Count < _poolSize) { context.Reset(); _contexts.Enqueue(context); } }
public bool Handle(ServerActionContext context, Exception error) { if (error is BoltServerException) { HandleBoltServerError(context, error as BoltServerException); return(true); } return(false); }
public bool Handle(ServerActionContext context, Exception error) { if (error is BoltServerException) { HandleBoltServerError(context, error as BoltServerException); return true; } return false; }
private ServerActionContext CreateContext(RouteContext routeContext) { ServerActionContext context; if (!_contexts.TryDequeue(out context)) { context = new ServerActionContext(); } context.Init(routeContext.HttpContext, Configuration); return(context); }
public virtual Task ExecuteAsync(ServerActionContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (Configuration != null) { context.Configuration.Merge(Configuration); } return Pipeline.Instance(context); }
public virtual Task ExecuteAsync(ServerActionContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (Configuration != null) { context.Configuration.Merge(Configuration); } return(Pipeline.Instance(context)); }
protected virtual void HandleBoltServerError(ServerActionContext actionContext, BoltServerException error) { int statusCode = 500; var response = actionContext.HttpContext.Response; response.StatusCode = statusCode; if (error.ErrorCode != null) { response.Headers[actionContext.Configuration.Options.ServerErrorHeader] = error.ErrorCode.Value.ToString(CultureInfo.InvariantCulture); } else if (error.Error != null) { response.Headers[actionContext.Configuration.Options.ServerErrorHeader] = error.Error.Value.ToString(); } LogBoltServerError(actionContext, error); }
protected virtual void HandleBoltServerError(ServerActionContext actionContext, BoltServerException error) { int statusCode = 500; var response = actionContext.HttpContext.Response; response.StatusCode = statusCode; if (error.ErrorCode != null) { response.Headers[actionContext.Configuration.Options.ServerErrorHeader] = error.ErrorCode.Value.ToString(CultureInfo.InvariantCulture); } else if (error.ServerError != null) { response.Headers[actionContext.Configuration.Options.ServerErrorHeader] = error.ServerError.Value.ToString(); } LogBoltServerError(actionContext, error); }
private void LogBoltServerError(ServerActionContext context, BoltServerException error) { if (error.ServerError != null) { Logger.LogError( BoltLogId.RequestExecutionError, "Execution of '{0}' failed with Bolt error '{1}'", context.Action.Name, error.ServerError); } if (error.ErrorCode != null) { Logger.LogError( BoltLogId.RequestExecutionError, "Execution of '{0}' failed with error code '{1}'", context.Action.Name, error.ErrorCode); } }
private void LogBoltServerError(ServerActionContext context, BoltServerException error) { if (error.Error != null) { Logger.LogError( BoltLogId.RequestExecutionError, "Execution of '{0}' failed with Bolt error '{1}'", context.Action.Name, error.Error); } if (error.ErrorCode != null) { Logger.LogError( BoltLogId.RequestExecutionError, "Execution of '{0}' failed with error code '{1}'", context.Action.Name, error.ErrorCode); } }
protected virtual async Task ExecuteAsync(ServerActionContext ctxt) { using (Logger.BeginScope("Execute")) { Stopwatch watch = null; if (Logger.IsEnabled(LogLevel.Debug)) { watch = Stopwatch.StartNew(); } try { await ctxt.ContractInvoker.ExecuteAsync(ctxt); } catch (OperationCanceledException) { if (!ctxt.HttpContext.Response.HasStarted) { ctxt.HttpContext.Response.StatusCode = (int)HttpStatusCode.RequestTimeout; } Logger.LogWarning(BoltLogId.RequestCancelled, "Execution of action '{0}' on contract '{1}' has been aborted by client.", ctxt.Action.Name, ctxt.Contract.Name); } catch (Exception e) { Logger.LogError(BoltLogId.RequestExecutionError, "Execution of action '{0}' on contract '{1}' failed with error '{2}'", ctxt.Action.Name, ctxt.Contract.Name, e); throw; } finally { if (watch != null) { Logger.LogDebug(BoltLogId.RequestExecutionTime, "Execution of action '{0}' on contract '{1}' has taken '{2}ms'", ctxt.Action.Name, ctxt.Contract.Name, watch.ElapsedMilliseconds); } } } }
protected virtual IBoltFeature AssignBoltFeature(ServerActionContext actionContext) { actionContext.HttpContext.Features.Set <IBoltFeature>(actionContext); return(actionContext); }