-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy patherror.go
46 lines (40 loc) · 1.08 KB
/
error.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
42
43
44
45
46
// Code generated for API Clients. DO NOT EDIT.
package ngrok
import (
"fmt"
"net/http"
)
// Returns true if the error is a not found response from the ngrok API.
func IsNotFound(err error) bool {
if ee, ok := err.(*Error); ok {
return int(ee.StatusCode) == http.StatusNotFound
}
return false
}
// Returns true if the given error is caused by any of the specified ngrok error codes.
// All ngrok error codes are documented at https://ngrok.com/docs/errors
func IsErrorCode(err error, codes ...int) bool {
if ee, ok := err.(*Error); ok {
for _, code := range codes {
if ee.ErrorCode == fmt.Sprintf("ERR_NGROK_%d", code) {
return true
}
}
}
return false
}
func (e *Error) Error() string {
msg := fmt.Sprintf("HTTP %d: %s", e.StatusCode, e.Msg)
if e.ErrorCode != "" {
msg += fmt.Sprintf(" [%s]", e.ErrorCode)
}
if e.OperationID() != "" {
msg += fmt.Sprintf("\n\nOperation ID: %s", e.OperationID())
}
return msg
}
// OperationID returns the unique trace ID assigned by ngrok to this API
// request.
func (e *Error) OperationID() string {
return e.Details["operation_id"]
}