~handlerug/handlebot

ref: e2138e35984f582b50a481b58c332afae2841b1f handlebot/wolframalpha/errors.go -rw-r--r-- 1.2 KiB
e2138e35Umar Getagazov urlpreview: Parse Content-Disposition 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
60
61
62
63
64
65
66
package wolframalpha

import (
	"fmt"
	"sort"
	"strings"
)

type PublicError interface {
	Public()
}

type NoResultsError struct {
	Err         error
	DidYouMeans DidYouMeans
}

func (e *NoResultsError) Error() string {
	var b strings.Builder
	b.WriteString("Wolfram|Alpha doesn't understand your query.")
	if e.DidYouMeans != nil && len(e.DidYouMeans) > 0 {
		didYouMeans := make(DidYouMeans, len(e.DidYouMeans))
		copy(didYouMeans, e.DidYouMeans)
		sort.Sort(didYouMeans)
		fmt.Fprintf(&b, " Did you mean: %s?", didYouMeans)
	}
	return b.String()
}

func (e *NoResultsError) Unwrap() error {
	return e.Err
}

func (e *NoResultsError) Public() {}

type TimeoutError struct{}

func (e *TimeoutError) Error() string {
	return "request to Wolfram|Alpha API timed out"
}

func (e *TimeoutError) Public() {}

type RequestError struct {
	Err error
}

func (e *RequestError) Error() string {
	return fmt.Sprintf("failed to send the request: %v", e.Err)
}

func (e *RequestError) Unwrap() error {
	return e.Err
}

type ResponseError struct {
	Err error
}

func (e *ResponseError) Error() string {
	return fmt.Sprintf("failed to read the response: %v", e.Err)
}

func (e *ResponseError) Unwrap() error {
	return e.Err
}