forked from abdullahselek/go-here
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
41 lines (37 loc) · 1.09 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
package here
import (
"fmt"
"time"
)
// APIError represents a HERE API Error response
type APIError struct {
ErrorType string `json:"_type"`
Type string `json:"type"`
Subtype string `json:"subtype"`
Details string `json:"details"`
MetaInfo struct {
Timestamp time.Time `json:"timestamp"`
MapVersion string `json:"mapVersion"`
ModuleVersion string `json:"moduleVersion"`
InterfaceVersion string `json:"interfaceVersion"`
AvailableMapVersion []string `json:"availableMapVersion"`
} `json:"metaInfo"`
}
func (e APIError) Error() string {
if len(e.Details) > 0 {
return fmt.Sprintf("go-here: %v %v", e.ErrorType, e.Details)
}
return ""
}
// relevantError returns any non-nil http-related error (creating the request,
// getting the response, decoding) if any. If the decoded apiError is non-zero
// the apiError is returned. Otherwise, no errors occurred, returns nil.
func relevantError(httpError error, apiError APIError) error {
if httpError != nil {
return httpError
}
if len(apiError.ErrorType) > 0 {
return apiError
}
return nil
}