~handlerug/handlebot

ref: 5c3342e9f8fd6f47e7bc4ff496b631441fce047a handlebot/weather/errors.go -rw-r--r-- 1021 bytes
5c3342e9Umar Getagazov Update README.md 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package weather

import (
	"fmt"
	"strings"
)

type PublicError interface {
	Public()
}

type ErrorMessages []string

func (m ErrorMessages) String() string {
	if len(m) == 0 {
		return "(no messages)"
	} else if len(m) == 1 {
		return m[0]
	} else {
		var b strings.Builder
		for i, msg := range m {
			if i > 0 {
				b.WriteString(", ")
			}
			fmt.Fprintf(&b, "%q", msg)
		}
		return b.String()
	}
}

type QuotaReachedError struct {
	APIName  string
	Messages ErrorMessages
}

func (e *QuotaReachedError) Error() string {
	return fmt.Sprintf("%s API quota reached: %s", e.APIName, e.Messages)
}

func (e *QuotaReachedError) Public() {}

type GeocodingError struct {
	Status   int
	Messages ErrorMessages
}

func (e *GeocodingError) Error() string {
	return fmt.Sprintf("geocoding failed with status %d: %s", e.Status, e.Messages)
}

func (e *GeocodingError) Public() {}

type NoGeocodeResults struct{}

func (e *NoGeocodeResults) Error() string {
	return "no geocode results"
}

func (e *NoGeocodeResults) Public() {}