{"record":{"id":"a35dab7fe4f5dcc6","repo":"GoogleCloudPlatform/microservices-demo","slug":"failed-to-create-request","errorCode":null,"errorMessage":"failed to create request","messagePattern":"failed to create request","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"src/frontend/handlers.go","lineNumber":467,"sourceCode":"}\n\nfunc (fe *frontendServer) chatBotHandler(w http.ResponseWriter, r *http.Request) {\n\tlog := r.Context().Value(ctxKeyLog{}).(logrus.FieldLogger)\n\ttype Response struct {\n\t\tMessage string `json:\"message\"`\n\t}\n\n\ttype LLMResponse struct {\n\t\tContent string         `json:\"content\"`\n\t\tDetails map[string]any `json:\"details\"`\n\t}\n\n\tvar response LLMResponse\n\n\turl := \"http://\" + fe.shoppingAssistantSvcAddr\n\treq, err := http.NewRequest(http.MethodPost, url, r.Body)\n\tif err != nil {\n\t\trenderHTTPError(log, r, w, errors.Wrap(err, \"failed to create request\"), http.StatusInternalServerError)\n\t\treturn\n\t}\n\treq.Header.Set(\"Content-Type\", \"application/json\")\n\treq.Header.Set(\"Accept\", \"application/json\")\n\tres, err := http.DefaultClient.Do(req)\n\tif err != nil {\n\t\trenderHTTPError(log, r, w, errors.Wrap(err, \"failed to send request\"), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tbody, err := io.ReadAll(res.Body)\n\tif err != nil {\n\t\trenderHTTPError(log, r, w, errors.Wrap(err, \"failed to read response\"), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tfmt.Printf(\"%+v\\n\", body)\n\tfmt.Printf(\"%+v\\n\", res)","sourceCodeStart":449,"sourceCodeEnd":485,"githubUrl":"https://github.com/GoogleCloudPlatform/microservices-demo/blob/72ba613a05f7fcee51cf1d0badff401b6ae7074d/src/frontend/handlers.go#L449-L485","documentation":"http.NewRequest failed while building the POST request to the shopping assistant service. Only fires with a malformed URL (e.g. empty or invalid shoppingAssistantSvcAddr composed into \"http://...\"), not with network problems, which surface later at Do().","triggerScenarios":"Thrown at src/frontend/handlers.go:467 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Validate fe.shoppingAssistantSvcAddr at startup; reject empty or malformed addresses.","Use url.Parse to validate the composed URL before http.NewRequest.","Fix the service address flag/env in the deployment configuration."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"72ba613a05f7fcee51cf1d0badff401b6ae7074d","analyzedAt":"2026-09-02T01:15:09.673Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}