public void Configure(ProblemDetailsOptions options) { if (options.IncludeExceptionDetails is null) { options.IncludeExceptionDetails = IncludeExceptionDetails; } if (options.ShouldLogUnhandledException is null) { options.ShouldLogUnhandledException = (ctx, e, d) => IsServerError(d.Status); } if (options.MapStatusCode is null) { options.MapStatusCode = ctx => StatusCodeProblemDetails.Create(ctx.Response.StatusCode); } if (options.IsProblem is null) { options.IsProblem = IsProblem; } if (options.GetTraceId is null) { options.GetTraceId = ctx => Activity.Current?.Id ?? ctx.TraceIdentifier; } if (options.ContentTypes.Count == 0) { options.ContentTypes.Add("application/problem+json"); options.ContentTypes.Add("application/problem+xml"); } }
public void Configure(ProblemDetailsOptions options) { if (options.IncludeExceptionDetails is null) { options.IncludeExceptionDetails = IncludeExceptionDetails; } if (options.ShouldLogUnhandledException is null) { options.ShouldLogUnhandledException = (ctx, e, d) => IsServerError(d.Status); } if (options.MapStatusCode is null) { options.MapStatusCode = ctx => StatusCodeProblemDetails.Create(ctx.Response.StatusCode); } if (options.IsProblem is null) { options.IsProblem = IsProblem; } if (options.GetTraceId is null) { options.GetTraceId = ctx => Activity.Current?.Id ?? ctx.TraceIdentifier; } if (string.IsNullOrEmpty(options.TraceIdPropertyName)) { options.TraceIdPropertyName = ProblemDetailsOptions.DefaultTraceIdPropertyName; } if (string.IsNullOrEmpty(options.ExceptionDetailsPropertyName)) { options.ExceptionDetailsPropertyName = ProblemDetailsOptions.DefaultExceptionDetailsPropertyName; } if (options.AppendCacheHeaders is null) { options.AppendCacheHeaders = (_, headers) => { headers[HeaderNames.CacheControl] = "no-cache, no-store, must-revalidate"; headers[HeaderNames.Pragma] = "no-cache"; headers[HeaderNames.ETag] = default; headers[HeaderNames.Expires] = "0"; }; } if (options.ContentTypes.Count == 0) { options.ContentTypes.Add("application/problem+json"); options.ContentTypes.Add("application/problem+xml"); } }
private static void SetProblemDetailsDefault( MvcProblemDetails result, int statusCode, string?title = null, string?type = null, string?detail = null, string?instance = null) { result.Status = statusCode; result.Title = title ?? result.Title; result.Type = type ?? result.Type ?? StatusCodeProblemDetails.GetDefaultType(statusCode); result.Detail = detail ?? result.Detail; result.Instance = instance ?? result.Instance; }
/// <summary> /// Maps the specified exception type <typeparamref name="TException"/> to the specified /// status code <paramref name="statusCode"/>. This also includes default values for /// <see cref="MvcProblemDetails.Type"/> and <see cref="MvcProblemDetails.Title"/>. /// </summary> /// <param name="statusCode">The status code to return for the specified exception.</param> /// <typeparam name="TException">The exception type to map to the specified status code.</typeparam> public void MapToStatusCode <TException>(int statusCode) where TException : Exception { Map <TException>((_, _) => StatusCodeProblemDetails.Create(statusCode)); }
public ProblemDetailsException(int statusCode, string title, Exception innerException) : this(StatusCodeProblemDetails.Create(statusCode, title), innerException) { }
public ProblemDetailsException(int statusCode, string title) : this(StatusCodeProblemDetails.Create(statusCode, title), null) { }
public ProblemDetailsException(int statusCode) : this(StatusCodeProblemDetails.Create(statusCode)) { }