-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
43 lines (38 loc) · 1.08 KB
/
errors.go
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
package yahoofinance
import (
"bytes"
"fmt"
"net/http"
)
// Error contains an error response from the server.
type Error struct {
// Code is the HTTP response status code and will always be populated.
Code int `json:"code,omitempty"`
// Message is the server response message and is only populated when
// explicitly referenced by the JSON server response.
Message string `json:"message,omitempty"`
// Body is the raw response returned by the server.
// It is often but not always JSON, depending on how the request fails.
Body string
// Header contains the response header fields from the server.
Header http.Header
}
func (e *Error) Error() string {
if e.Message == "" {
return fmt.Sprintf("API: got HTTP response code %d with body: %v", e.Code, e.Body)
}
var buf bytes.Buffer
fmt.Fprintf(&buf, "API: Error %d: ", e.Code)
if e.Message != "" {
fmt.Fprintf(&buf, "%s", e.Message)
}
return buf.String()
}
type errorReply struct {
Chart struct {
Error struct {
Code string `json:"code"`
Description string `json:"description"`
} `json:"error"`
} `json:"chart"`
}