summaryrefslogtreecommitdiff
path: root/golang/pkg/api/errors.go
blob: d39a205e1778deda3d69735eee9da4bb2708da9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
}