-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
43 lines (33 loc) · 1.04 KB
/
errors.go
File metadata and controls
43 lines (33 loc) · 1.04 KB
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 devicebase
import "fmt"
// Error is the base error type for all DeviceBase SDK errors.
type Error struct {
Message string
StatusCode int
}
func (e *Error) Error() string { return e.Message }
// AuthenticationError is returned when the API key is missing or invalid.
type AuthenticationError struct {
Message string
StatusCode int
}
func (e *AuthenticationError) Error() string { return e.Message }
// DeviceNotFoundError is returned when the device is not found or not connected.
type DeviceNotFoundError struct {
Message string
StatusCode int
}
func (e *DeviceNotFoundError) Error() string { return e.Message }
// ValidationError is returned when request validation fails.
type ValidationError struct {
Message string
StatusCode int
}
func (e *ValidationError) Error() string { return e.Message }
// newError creates a base Error from an HTTP status and body.
func newError(statusCode int, body string) error {
return &Error{
Message: fmt.Sprintf("API error: %d - %s", statusCode, body),
StatusCode: statusCode,
}
}