summaryrefslogtreecommitdiff
path: root/golang/pkg/api/errors.go
blob: 2e36f161ecbcdc464225b8ece308feb058d12a26 (plain)
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
package api

import (
	"encoding/json"
	"fmt"
	"time"
)

// ----- 429 --------------------------------------------------------------------
type RateLimitError struct {
	LimitType      string    `json:"type"`
	RetryAfter     Duration  `json:"retryAfter"`
	LimitBurst     int       `json:"limitBurst"`
	LimitPerSecond int       `json:"limitPerSecond"`
	Remaining      int       `json:"remaining"`
	Reset          time.Time `json:"reset"`
}

func decodeRateLimitError(msg json.RawMessage) RateLimitError {
	var e RateLimitError
	if err := json.Unmarshal(msg, &e); err != nil {
		panic(fmt.Errorf("Failed to decode iapi error code 429 RateLimitError: %v, %w", msg, err))
	}
	return e
}

// ----- 4214 -------------------------------------------------------------------
type ShipInTransitError struct {
	Arrival           time.Time `json:"arrival"`
	DepartureSymbol   string    `json:"departureSymbol"`
	DepartureTime     time.Time `json:"departureTime"`
	DestinationSymbol string    `json:"destinationSymbol"`
	SecondsToArrival  Duration  `json:"secondsToArrival"`
}

func decodeShipInTransitError(msg json.RawMessage) ShipInTransitError {
	var e ShipInTransitError
	if err := json.Unmarshal(msg, &e); err != nil {
		panic(fmt.Errorf("Failed to decode api error code 4214 ShipInTransitError: %v, %w", msg, err))
	}
	return e
}