GoogleCloudPlatform/microservices-demo · error
failed to create request
Error message
failed to create request
What it means
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().
Source
Thrown at src/frontend/handlers.go:467
}
func (fe *frontendServer) chatBotHandler(w http.ResponseWriter, r *http.Request) {
log := r.Context().Value(ctxKeyLog{}).(logrus.FieldLogger)
type Response struct {
Message string `json:"message"`
}
type LLMResponse struct {
Content string `json:"content"`
Details map[string]any `json:"details"`
}
var response LLMResponse
url := "http://" + fe.shoppingAssistantSvcAddr
req, err := http.NewRequest(http.MethodPost, url, r.Body)
if err != nil {
renderHTTPError(log, r, w, errors.Wrap(err, "failed to create request"), http.StatusInternalServerError)
return
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
renderHTTPError(log, r, w, errors.Wrap(err, "failed to send request"), http.StatusInternalServerError)
return
}
body, err := io.ReadAll(res.Body)
if err != nil {
renderHTTPError(log, r, w, errors.Wrap(err, "failed to read response"), http.StatusInternalServerError)
return
}
fmt.Printf("%+v\n", body)
fmt.Printf("%+v\n", res)View on GitHub (pinned to 72ba613a05)
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.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/frontend/handlers.go:467 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of GoogleCloudPlatform/microservices-demo@72ba613a05 (2026-09-02).
Data as JSON: /api/errors/a35dab7fe4f5dcc6.
Report an issue: GitHub.