Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Roads: Nearby Roads does not give error when trying to issue request without billing setup #246

Open
twa16 opened this issue Oct 4, 2020 · 2 comments
Labels
help wanted We'd love to have community involvement on this issue. priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@twa16
Copy link

twa16 commented Oct 4, 2020

Call to nearby roads API does not give same error about not having billing setup as the geocoding API does.

Steps to reproduce

  1. Create a basic project requesting snap to roads
  2. Use API key associated with project that does not have billing enabled.
  3. Issue request

One will get an empty response but no error. The geocoding API does return an error stating that billing must be enabled.

Code example

c, err := maps.NewClient(maps.WithAPIKey(os.Getenv("GOOGLE_MAPS_API_KEY")))
	if err != nil {
		log.Fatalf("fatal error: %s", err)
	}

	r := maps.NearestRoadsRequest{Points: utils.GeoPointsToGmapLatLngs(geoPoints)}

	resp, err := c.NearestRoads(context.Background(), &r)
	if err != nil {
		log.Fatalf("fatal error: %s", err)
	}

	pretty.Println(resp.SnappedPoints)

Stack trace

None

@twa16 twa16 added triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Oct 4, 2020
@AlphaWong
Copy link
Contributor

AlphaWong commented Oct 9, 2020

hi

May I confirm with you about the step to setup?

  1. create a project ( the billing is enabled by default )
  2. create an API key in by click Create credentials > API key.
  3. disable the billing for this project.

the error message will be shown as follow?

{
  "error": {
    "code": 404,
    "message": "Requested entity was not found.",
    "status": "NOT_FOUND"
  }
}

my raw query ( please replace YOU_KEY field )

curl --request GET \
  --url 'https://roads.googleapis.com/v1/nearestRoads?points=60.170880%2C24.942795%7C60.170879%2C24.942796%7C60.170877%2C24.942796&key=YOU_KEY'

my guess

I think it did throw an error, you can find err = json.NewDecoder(httpResp.Body).Decode(resp) will return an error as the response with error cannot mapped to resp which is a reference from response := &NearestRoadsResponse{}

func (c *Client) getJSON(ctx context.Context, config *apiConfig, apiReq apiRequest, resp interface{}) error {
	requestMetrics := c.metricReporter.NewRequest(config.path)
	httpResp, err := c.get(ctx, config, apiReq)
	if err != nil {
		requestMetrics.EndRequest(ctx, err, httpResp, "")
		return err
	}
	defer httpResp.Body.Close()

	err = json.NewDecoder(httpResp.Body).Decode(resp)
	requestMetrics.EndRequest(ctx, err, httpResp, httpResp.Header.Get("x-goog-maps-metro-area"))
	return err
}

@twa16
Copy link
Author

twa16 commented Oct 10, 2020

Thanks for the response. I agree that the underlying raw API call throws the error. I think the issue is that unlike the geocoding go call, the error does not get propagated up to the developer. There may very well be an internal error but to the developer using the gmaps golang library, it looks like a silent failure.

As for reproduction, billing was not enabled by default but I imagine having a project with billing explicitly disabled will reproduce the issue.

@jpoehnelt jpoehnelt added priority: p3 Desirable enhancement or fix. May not be included in next release. help wanted We'd love to have community involvement on this issue. and removed triage me I really want to be triaged. labels Jan 21, 2021
@jpoehnelt jpoehnelt removed their assignment Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted We'd love to have community involvement on this issue. priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

3 participants