-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlink_check_error.go
More file actions
38 lines (33 loc) · 754 Bytes
/
link_check_error.go
File metadata and controls
38 lines (33 loc) · 754 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
package hype
import (
"encoding/json"
"fmt"
)
type LinkCheckError struct {
URL string
StatusCode int
Err error
}
func (e LinkCheckError) Error() string {
if e.StatusCode > 0 {
return fmt.Sprintf("link check failed for %q: status %d", e.URL, e.StatusCode)
}
if e.Err != nil {
return fmt.Sprintf("link check failed for %q: %s", e.URL, e.Err)
}
return fmt.Sprintf("link check failed for %q", e.URL)
}
func (e LinkCheckError) Unwrap() error {
return e.Err
}
func (e LinkCheckError) MarshalJSON() ([]byte, error) {
m := map[string]any{
"type": "link_check_error",
"url": e.URL,
"status_code": e.StatusCode,
}
if e.Err != nil {
m["error"] = e.Err.Error()
}
return json.MarshalIndent(m, "", " ")
}