-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy patherror.go
More file actions
48 lines (41 loc) · 1.25 KB
/
error.go
File metadata and controls
48 lines (41 loc) · 1.25 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
44
45
46
47
48
package onfleet
import (
"encoding/json"
"fmt"
"io"
)
type RequestErrorMessage struct {
Cause any `json:"cause,omitempty"`
// Error is an internal error code.
// It is different than the request status code.
Error int `json:"error,omitempty"`
// Message is the error messages / description
Message string `json:"message,omitempty"`
// RemoteAddress is remote ip
RemoteAddress string `json:"remoteAddress,omitempty"`
// Request is uuid associated with the request
Request string `json:"request,omitempty"`
// StatusCode only present on errors returned for batch task creation
StatusCode int `json:"statusCode,omitempty"`
}
type RequestError struct {
// Code is error type e.g. "InvalidArgument"
Code string `json:"code,omitempty"`
// Message contains futher details about the error.
Message RequestErrorMessage `json:"message"`
}
func (err RequestError) Error() string {
return fmt.Sprintf("%s: \n Cause: %s\n Message: %s", err.Code, err.Message.Cause, err.Message.Message)
}
func ParseError(r io.Reader) error {
var reqError RequestError
if err := json.NewDecoder(r).Decode(&reqError); err != nil {
return err
}
return reqError
}
type TooManyRequestsError struct {
}
func (err TooManyRequestsError) Error() string {
return "too many requests"
}