{"record":{"id":"20e04e67e50002bc","repo":"dotnetcore/CAP","slug":"error-when-parsing-incoming-request-exception-ex-message","errorCode":null,"errorMessage":"Error when parsing incoming request, exception: {ex.Message}","messagePattern":"Error when parsing incoming request, exception: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/DotNetCore.CAP.Dashboard/GatewayProxy/IRequestMapper.Default.cs","lineNumber":38,"sourceCode":"\n    public async Task<HttpRequestMessage> Map(HttpRequest request)\n    {\n        try\n        {\n            var requestMessage = new HttpRequestMessage\n            {\n                Content = await MapContent(request),\n                Method = MapMethod(request),\n                RequestUri = MapUri(request)\n            };\n\n            MapHeaders(request, requestMessage);\n\n            return requestMessage;\n        }\n        catch (Exception ex)\n        {\n            throw new Exception($\"Error when parsing incoming request, exception: {ex.Message}\");\n        }\n    }\n\n    private string BuildAbsolute(\n        string scheme,\n        HostString host,\n        PathString pathBase = new(),\n        PathString path = new(),\n        QueryString query = new(),\n        FragmentString fragment = new())\n    {\n        if (scheme == null) throw new ArgumentNullException(nameof(scheme));\n\n        var combinedPath = pathBase.HasValue || path.HasValue ? (pathBase + path).ToString() : \"/\";\n\n        var encodedHost = host.ToString();\n        var encodedQuery = query.ToString();\n        var encodedFragment = fragment.ToString();","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/dotnetcore/CAP/blob/e52b8508e54cdb7a9ce7f9fec03d9ea8ad2710fb/src/DotNetCore.CAP.Dashboard/GatewayProxy/IRequestMapper.Default.cs#L20-L56","documentation":"The Dashboard's default IRequestMapper (Map method) wraps any failure while converting the incoming HttpRequest into an HttpRequestMessage in a generic Exception: \"Error when parsing incoming request, exception: {ex.Message}\". The inner message (e.g. a null-scheme ArgumentNullException from BuildAbsolute) is the real cause; only ex.Message is preserved, so the original stack trace and type are lost.","triggerScenarios":"Any exception inside Map's try block when building the proxied request: MapHeaders, BuildAbsolute/GetEncodedUrl failures (e.g. null scheme), malformed request Uri construction against the dashboard node.","commonSituations":"Accessing the Dashboard through a reverse proxy that strips the scheme, misconfigured forwarded headers, or unusual request URLs that make UriBuilder/GetEncodedUrl throw.","solutions":["Inspect the inner '{ex.Message}' text to identify the real cause (e.g. 'Parameter scheme') and fix the incoming request configuration.","Ensure ForwardedHeaders middleware is configured so HttpContext.Request.Scheme is populated behind a proxy.","Change the wrapper to throw with InnerException preserved: throw new Exception(msg, ex) for diagnosability.","Log the full exception server-side instead of only ex.Message."],"exampleFix":"// before\nthrow new Exception($\"Error when parsing incoming request, exception: {ex.Message}\");\n// after\nthrow new Exception(\"Error when parsing incoming request\", ex); // preserves type + stack","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    var req = await mapper.MapAsync(request);\n}\ncatch (Exception ex) when (ex.Message.StartsWith(\"Error when parsing incoming request\"))\n{\n    logger.LogError(ex, \"Dashboard request mapping failed: {Message}\", ex.Message);\n    return StatusCode(400);\n}","preventionTips":["Configure ForwardedHeaders so Scheme/Host are populated behind proxies","Log the full exception, not just ex.Message","Test the dashboard through the same proxy topology used in production"],"tags":["request-parsing","wrapper-exception","dashboard","proxy","http"],"backgroundTag":"http-request-failed","analyzedSha":"e52b8508e54cdb7a9ce7f9fec03d9ea8ad2710fb","analyzedAt":"2026-09-14T14:46:34.677Z","contentChangedAt":"2026-09-14T14:46:34.677Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}