<commit_before>package osmapi

import (
	"encoding/xml"
	"fmt"
	"net/http"
	"time"

	"golang.org/x/net/context"
	"golang.org/x/net/context/ctxhttp"
)

const host = "http://api.openstreetmap.org/api/0.6"

var httpClient = &http.Client{
	Timeout: 6 * time.Minute, // looks like the api server has a 5 min timeout.
}

func getFromAPI(ctx context.Context, url string, item interface{}) error {
	resp, err := ctxhttp.Get(ctx, httpClient, url)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	if resp.StatusCode == http.StatusNotFound {
		return ErrNotFound{URL: url}
	}

	if resp.StatusCode == http.StatusForbidden {
		return ErrForbidden{URL: url}
	}

	if resp.StatusCode == http.StatusGone {
		return ErrGone{URL: url}
	}

	if resp.StatusCode != http.StatusOK {
		return ErrUnexpectedStatusCode{
			Code: resp.StatusCode,
			URL:  url,
		}
	}

	return xml.NewDecoder(resp.Body).Decode(item)
}

// ErrNotFound means 404 from the api.
type ErrNotFound struct {
	URL string
}

// Error returns an error message with the url causing the problem.
func (e ErrNotFound) Error() string {
	return fmt.Sprintf("osmapi: not found at %s", e.URL)
}

// ErrForbidden means 403 from the api.
// Returned whenever the version of the element is not available (due to redaction).
type ErrForbidden struct {
	URL string
}

// Error returns an error message with the url causing the problem.
func (e ErrForbidden) Error() string {
	return fmt.Sprintf("osmapi: forbidden at %s", e.URL)
}

// ErrGone is returned for deleted elements that get 410 from the api.
type ErrGone struct {
	URL string
}

// Error returns an error message with the url causing the problem.
func (e ErrGone) Error() string {
	return fmt.Sprintf("osmapi: gone at %s", e.URL)
}

// ErrUnexpectedStatusCode is return for a non 200 or 404 status code.
type ErrUnexpectedStatusCode struct {
	Code int
	URL  string
}

// Error returns an error message with some information.
func (e ErrUnexpectedStatusCode) Error() string {
	return fmt.Sprintf("osmapi: unexpected status code of %d for url %s", e.Code, e.URL)
}
<commit_msg>Return pointers to osmapi errors, as is customary<commit_after>package osmapi

import (
	"encoding/xml"
	"fmt"
	"net/http"
	"time"

	"golang.org/x/net/context"
	"golang.org/x/net/context/ctxhttp"
)

const host = "http://api.openstreetmap.org/api/0.6"

var httpClient = &http.Client{
	Timeout: 6 * time.Minute, // looks like the api server has a 5 min timeout.
}

func getFromAPI(ctx context.Context, url string, item interface{}) error {
	resp, err := ctxhttp.Get(ctx, httpClient, url)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	if resp.StatusCode == http.StatusNotFound {
		return &ErrNotFound{URL: url}
	}

	if resp.StatusCode == http.StatusForbidden {
		return &ErrForbidden{URL: url}
	}

	if resp.StatusCode == http.StatusGone {
		return &ErrGone{URL: url}
	}

	if resp.StatusCode != http.StatusOK {
		return &ErrUnexpectedStatusCode{
			Code: resp.StatusCode,
			URL:  url,
		}
	}

	return xml.NewDecoder(resp.Body).Decode(item)
}

// ErrNotFound means 404 from the api.
type ErrNotFound struct {
	URL string
}

// Error returns an error message with the url causing the problem.
func (e ErrNotFound) Error() string {
	return fmt.Sprintf("osmapi: not found at %s", e.URL)
}

// ErrForbidden means 403 from the api.
// Returned whenever the version of the element is not available (due to redaction).
type ErrForbidden struct {
	URL string
}

// Error returns an error message with the url causing the problem.
func (e ErrForbidden) Error() string {
	return fmt.Sprintf("osmapi: forbidden at %s", e.URL)
}

// ErrGone is returned for deleted elements that get 410 from the api.
type ErrGone struct {
	URL string
}

// Error returns an error message with the url causing the problem.
func (e ErrGone) Error() string {
	return fmt.Sprintf("osmapi: gone at %s", e.URL)
}

// ErrUnexpectedStatusCode is return for a non 200 or 404 status code.
type ErrUnexpectedStatusCode struct {
	Code int
	URL  string
}

// Error returns an error message with some information.
func (e ErrUnexpectedStatusCode) Error() string {
	return fmt.Sprintf("osmapi: unexpected status code of %d for url %s", e.Code, e.URL)
}

{'fraction_non_alphanumeric': 0.10738095238095238, 'fraction_numerical': 0.009047619047619047, 'mean_word_length': 3.8176605504587156, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '758041', 'n_tokens_mistral': 1425, 'n_tokens_neox': 1369, 'n_words': 485}