-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
38 lines (33 loc) · 989 Bytes
/
Copy patherrors.go
File metadata and controls
38 lines (33 loc) · 989 Bytes
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
package twse
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:"rtmessage,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 {
Message string `json:"rtmessage"`
}