Skip to content

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

Open

Description

@twa16

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

Activity

  1. added
    triage meI really want to be triaged.
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    on Oct 4, 2020
  2. AlphaWong commented on Oct 9, 2020

    @AlphaWong
    Contributor

    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
    }
  3. twa16 commented on Oct 10, 2020

    @twa16
    Author

    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.

  4. added
    priority: p3Desirable enhancement or fix. May not be included in next release.
    help wantedWe'd love to have community involvement on this issue.
    and removed
    triage meI really want to be triaged.
    on Jan 21, 2021
  5. removed their assignment
    on Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedWe'd love to have community involvement on this issue.priority: p3Desirable enhancement or fix. May not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions