forked from zoom-lib-golang/zoom-lib-golang
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherror.go
More file actions
42 lines (34 loc) · 759 Bytes
/
error.go
File metadata and controls
42 lines (34 loc) · 759 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
39
40
41
42
package zoom
import (
"encoding/json"
"fmt"
)
type errorContainer struct {
*APIError
}
// APIError contains the code and message returned by any Zoom errors
type APIError struct {
Code int `json:"code"`
Message string `json:"message"`
Errors []struct {
Field string `json:"field"`
Message string `json:"message"`
} `json:"errors,omitempty"`
}
func (e *APIError) Error() string {
if e == nil {
return ""
}
return fmt.Sprintf("Zoom API error %d: \"%s\"", e.Code, e.Message)
}
func checkError(body []byte) error {
var c errorContainer
if err := json.Unmarshal(body, &c); err != nil {
return err
}
// need to explicitly return nil or it will register as an error
if c.APIError == nil {
return nil
}
return c.APIError
}