{"record":{"id":"5531ac8600d96550","repo":"GoogleCloudPlatform/microservices-demo","slug":"failed-to-convert-currency","errorCode":null,"errorMessage":"failed to convert currency","messagePattern":"failed to convert currency","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"src/frontend/handlers.go","lineNumber":173,"sourceCode":"\tif err != nil {\n\t\trenderHTTPError(log, r, w, errors.Wrap(err, \"could not retrieve product\"), http.StatusInternalServerError)\n\t\treturn\n\t}\n\tcurrencies, err := fe.getCurrencies(r.Context())\n\tif err != nil {\n\t\trenderHTTPError(log, r, w, errors.Wrap(err, \"could not retrieve currencies\"), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tcart, err := fe.getCart(r.Context(), sessionID(r))\n\tif err != nil {\n\t\trenderHTTPError(log, r, w, errors.Wrap(err, \"could not retrieve cart\"), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tprice, err := fe.convertCurrency(r.Context(), p.GetPriceUsd(), currentCurrency(r))\n\tif err != nil {\n\t\trenderHTTPError(log, r, w, errors.Wrap(err, \"failed to convert currency\"), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\t// ignores the error retrieving recommendations since it is not critical\n\trecommendations, err := fe.getRecommendations(r.Context(), sessionID(r), []string{id})\n\tif err != nil {\n\t\tlog.WithField(\"error\", err).Warn(\"failed to get product recommendations\")\n\t}\n\n\tproduct := struct {\n\t\tItem  *pb.Product\n\t\tPrice *pb.Money\n\t}{p, price}\n\n\t// Fetch packaging info (weight/dimensions) of the product\n\t// The packaging service is an optional microservice you can run as part of a Google Cloud demo.\n\tvar packagingInfo *PackagingInfo = nil\n\tif isPackagingServiceConfigured() {","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/GoogleCloudPlatform/microservices-demo/blob/72ba613a05f7fcee51cf1d0badff401b6ae7074d/src/frontend/handlers.go#L155-L191","documentation":"The productHandler failed to convert the product's USD price into the user's selected currency via fe.convertCurrency (currencyservice Convert RPC). The error is wrapped and rendered as an HTTP 500 page. It means the currency conversion RPC failed or the currency code is invalid.","triggerScenarios":"GET /product/{id} with a currency cookie/currency param that currencyservice cannot convert, or the Convert RPC returning an error/timeout.","commonSituations":"currencyservice down, unsupported currency code in the user's cookie (e.g. stale cookie after currency list change), request context canceled mid-conversion.","solutions":["Check currencyservice availability and its logs.","Validate the currentCurrency value against fe.getCurrencies() before converting.","Clear/fix the user's currency cookie to a supported code.","Increase timeouts or check network connectivity to currencyservice."],"exampleFix":"// before\nprice, err := fe.convertCurrency(ctx, p.GetPriceUsd(), currentCurrency(r))\n// after\nsupported, _ := fe.getCurrencies(ctx)\nif !containsCurrency(supported, currentCurrency(r)) {\n    log.Warn(\"unsupported currency, falling back to USD\")\n}\nprice, err := fe.convertCurrency(ctx, p.GetPriceUsd(), currentCurrency(r))","handlingStrategy":"validation","validationCode":"supported, err := fe.getCurrencies(ctx)\nif err == nil && !containsCurrency(supported, currentCurrency(r)) {\n    log.Warn(\"unsupported currency requested, defaulting to USD\")\n}","typeGuard":"func supportedCurrency(code string, list []*pb.Currency) bool {\n    for _, c := range list { if code == c.Code { return true } }\n    return false\n}","tryCatchPattern":"price, err := fe.convertCurrency(r.Context(), p.GetPriceUsd(), currentCurrency(r))\nif err != nil {\n    log.WithField(\"error\", err).Warn(\"conversion failed, using USD price\")\n    usd := p.GetPriceUsd(); price = &usd\n}","preventionTips":["Validate the currency cookie against Supported before converting.","Cache the currency list; it rarely changes.","Set sane gRPC deadlines on Convert calls.","Alert on currencyservice error rates."],"tags":["grpc","http-500","currency","microservices"],"backgroundTag":"rpc-service-unavailable","analyzedSha":"72ba613a05f7fcee51cf1d0badff401b6ae7074d","analyzedAt":"2026-09-02T01:15:09.673Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}