diff options
Diffstat (limited to 'golang/pkg/api/errors.go')
-rw-r--r-- | golang/pkg/api/errors.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/golang/pkg/api/errors.go b/golang/pkg/api/errors.go new file mode 100644 index 0000000..d39a205 --- /dev/null +++ b/golang/pkg/api/errors.go @@ -0,0 +1,23 @@ +package api + +import ( + "encoding/json" + "fmt" + "time" +) + +type RateLimitError struct { + LimitType string `json:"type"` + RetryAfter float64 `json:"retryAfter"` + LimitBurst int `json:"limitBurst"` + LimitPerSecond int `json:"limitPerSecond"` + Remaining int `json:"remaining"` + Reset time.Time `json:"reset"` +} + +func decode429(msg []byte) (e APIMessage[any, RateLimitError]) { + if err := json.Unmarshal(msg, &e); err != nil { + panic(fmt.Sprintf("Failed to decode419: %+v", err)) + } + return e +} |