briandowns / openweathermap

Go (golang) package for use with openweathermap.org's API.
Apache License 2.0
240 stars 70 forks source link

Error upon non-existing places are unintuitive #68

Open oniichaNj opened 6 years ago

oniichaNj commented 6 years ago

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 commented 6 years ago

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

briandowns commented 6 years ago

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