internal static Error Create(Results.Error errorResult, IRequest request) { var resource = request.SafeSelect(a => a.Resource); var uri = request.UriComponents.ToString(); var errorStackTrace = errorResult.StackTrace; var innerStackTrace = errorResult.InnerException?.StackTrace; var nl = Environment.NewLine; var stackTrace = string.Join($"{nl}§§§ INNER: §§§{nl}", errorStackTrace, innerStackTrace); var totalMessage = errorResult.ToString(); var errorsToKeep = request .GetService <IConfiguration>()? .GetValue <int>("NrOfErrorsToKeep") ?? DefaultNumberOfErrorsToKeep; if (Counter > errorsToKeep && Counter % DeleteBatch == 0) { var cutoffId = Counter - errorsToKeep; var entitiesToDelete = InMemoryOperations <Error> .Select() .Where(existingError => existingError.Id <= cutoffId) .ToList(); InMemoryOperations <Error> .Delete(entitiesToDelete); } var error = new Error ( uri: uri, method: request.Method, headers: resource is IEntityResource { RequiresAuthentication: true }
internal static Error Create(Results.Error error, IRequest request) { var resource = request.SafeSelect(a => a.Resource); var uri = request.UriComponents.ToString(); var stackTrace = $"{error.StackTrace} §§§ INNER: {error.InnerException?.StackTrace}"; var totalMessage = error.TotalMessage(); return(new Error { Time = DateTime.UtcNow, ResourceName = (resource?.Name ?? "<unknown>") + (resource?.Alias != null ? $" ({resource.Alias})" : ""), Method = request.Method, ErrorCode = error.ErrorCode, Body = request.GetBody().ToString(), StackTrace = stackTrace.Length > MaxStringLength?stackTrace.Substring(0, MaxStringLength) : stackTrace, Message = totalMessage.Length > MaxStringLength?totalMessage.Substring(0, MaxStringLength) : totalMessage, Uri = uri, Headers = resource is IEntityResource e && e.RequiresAuthentication ? null : request.Headers.StringJoin(" | ", dict => dict.Select(header => { switch (header.Key.ToLower()) { case "authorization": return "Authorization: apikey *******"; case "x-original-url" when header.Value.Contains("key="): return "*******"; default: return $"{header.Key}: {header.Value}"; } })) });
private Result(bool isValue, Results.Error error, T value) { this.isValue = isValue; this.error = error; this.value = value; }
public static bool TryParse(string destinationHeader, out HeaderRequestParameters parameters, out Results.Error error) { try { parameters = new HeaderRequestParameters(destinationHeader); error = null; return(true); } catch (Results.Error _error) { parameters = null; error = _error; return(false); } catch (Exception exception) { parameters = null; error = exception.AsError(); return(false); } }