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

Error upon non-existing places are unintuitive #68

Open
oniichaNj opened this issue Jun 14, 2018 · 2 comments
Open

Error upon non-existing places are unintuitive #68

oniichaNj opened this issue Jun 14, 2018 · 2 comments

Comments

@oniichaNj
Copy link

oniichaNj commented Jun 14, 2018

Consider the following example;

package main

import (
	owm "github.com/briandowns/openweathermap"
	"log"
)

func main() {
	w, err := owm.NewCurrent("C", "en", "<redacted>")
	if err != nil {
		log.Fatal(err)
	}

	err = w.CurrentByName("St Petersburg")
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("Temperature in %s: %.1f °C\n", w.Name, w.Main.Temp)

	err = w.CurrentByName("fff")
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("Temperature in %s: %.1f °C\n", w.Name, w.Main.Temp)
}

This outputs json: cannot unmarshal string into Go struct field CurrentWeatherData.cod of type int as an error for the second CurrentByName call.
Perhaps a more descriptive error message could be used here?

@theodesp
Copy link
Contributor

The response of the particular query is 404 Not Found. Do you think we need to just map the response codes to messages?

@briandowns
Copy link
Owner

I would think that returning the provided location with the error would provide necessary context. Would more be needed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants