Exemplo n.º 1
0
        public string RewriteExceptionTypeFrom(ProblemDetails problemDetails)
        {
            var exceptionName = problemDetails
                                ?.ProblemTypeUri
                                .Split(":", StringSplitOptions.RemoveEmptyEntries)
                                .LastOrDefault();

            if (string.IsNullOrWhiteSpace(exceptionName))
            {
                return(string.Empty);
            }

            var exceptionType = AssemblyBuilder
                                .DefineDynamicAssembly(new AssemblyName("CustomProblemDetailsHelperAssembly"), AssemblyBuilderAccess.Run)
                                .DefineDynamicModule("CustomProblemDetailsHelperModule")
                                .DefineType(
                $"{exceptionName}Exception",
                TypeAttributes.Public | TypeAttributes.Class,
                typeof(Exception))
                                .CreateType();

            dynamic customException = Activator.CreateInstance(exceptionType ?? typeof(Exception)) ?? new Exception();

            return(GetExceptionTypeUriFor(customException));
        }
Exemplo n.º 2
0
 protected override ProblemDetails GetApiProblemFor(DomainException exception) =>
 new ProblemDetails
 {
     HttpStatus         = StatusCodes.Status400BadRequest,
     Title              = ProblemDetails.DefaultTitle,
     Detail             = exception.Message,
     ProblemTypeUri     = _problemDetailsHelper.GetExceptionTypeUriFor(exception),
     ProblemInstanceUri = $"{_problemDetailsHelper.GetInstanceBaseUri()}/{ProblemDetails.GetProblemNumber()}"
 };
Exemplo n.º 3
0
 protected override ProblemDetails GetApiProblemFor(HttpRequestException exception) =>
 new ProblemDetails
 {
     HttpStatus         = StatusCodes.Status503ServiceUnavailable,
     Title              = ProblemDetails.DefaultTitle,
     Detail             = exception.Message,
     ProblemTypeUri     = ProblemDetails.GetTypeUriFor(exception),
     ProblemInstanceUri = ProblemDetails.GetProblemNumber()
 };
Exemplo n.º 4
0
 protected override ProblemDetails GetApiProblemFor(AggregateNotFoundException exception) =>
 new ProblemDetails
 {
     HttpStatus         = StatusCodes.Status400BadRequest,
     Title              = "Deze actie is niet geldig!",
     Detail             = $"De resource met id '{exception.Identifier}' werd niet gevonden.",
     ProblemTypeUri     = ProblemDetails.GetTypeUriFor(exception),
     ProblemInstanceUri = ProblemDetails.GetProblemNumber()
 };
Exemplo n.º 5
0
 protected override ProblemDetails GetApiProblemFor(ApiException exception) =>
 new ProblemDetails
 {
     HttpStatus         = exception.StatusCode,
     Title              = ProblemDetails.DefaultTitle,
     Detail             = exception.Message,
     ProblemTypeUri     = ProblemDetails.GetTypeUriFor(exception),
     ProblemInstanceUri = ProblemDetails.GetProblemNumber()
 };
Exemplo n.º 6
0
 protected override ProblemDetails GetApiProblemFor(DBConcurrencyException exception) =>
 new ProblemDetails
 {
     HttpStatus         = StatusCodes.Status409Conflict,
     Title              = ProblemDetails.DefaultTitle,
     Detail             = exception.Message,
     ProblemTypeUri     = ProblemDetails.GetTypeUriFor(exception),
     ProblemInstanceUri = ProblemDetails.GetProblemNumber()
 };
Exemplo n.º 7
0
        public string GetInstanceUri(HttpContext httpContext)
        {
            // this is the same behaviour that Asp.Net core uses
            var traceId = Activity.Current?.Id ?? httpContext.TraceIdentifier;

            var problemBaseInstanceUri = GetInstanceBaseUri();

            return(!string.IsNullOrWhiteSpace(traceId)
                ? $"{problemBaseInstanceUri}/{Deterministic.Create(ProblemDetailsSeed, traceId):N}"
                : $"{problemBaseInstanceUri}/{ProblemDetails.GetProblemNumber()}");
        }
Exemplo n.º 8
0
 public ApiProblemDetailsException(string message, int statusCode, ProblemDetails problemDetails, Exception innerException)
     : base(message, statusCode, innerException)
 {
     Details = problemDetails ?? throw new ArgumentNullException(nameof(problemDetails));
 }
Exemplo n.º 9
0
 public static void SetTraceId(this ProblemDetails details, ProblemDetailsHelper problemDetailsHelper, HttpContext httpContext)
 => details.ProblemInstanceUri = problemDetailsHelper.GetInstanceUri(httpContext);
Exemplo n.º 10
0
 public string GetExceptionTypeUriFor <T>() where T : Exception
 => string.IsNullOrWhiteSpace(NamespaceOverride)
         ? ProblemDetails.GetTypeUriFor <T>()
 : ProblemDetails.GetTypeUriFor <T>(NamespaceOverride);
Exemplo n.º 11
0
 public static void SetTraceId(ProblemDetails details, HttpContext httpContext)
 => details.ProblemInstanceUri = httpContext.GetProblemInstanceUri();