tgerr

package
v0.95.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 21, 2024 License: MIT Imports: 8 Imported by: 66

Documentation

Overview

Package tgerr implements helpers for error handling.

Index

Constants

View Source
const ErrFloodWait = "FLOOD_WAIT"

ErrFloodWait is error type of "FLOOD_WAIT" error.

Variables

This section is empty.

Functions

func AsFloodWait added in v0.41.0

func AsFloodWait(err error) (d time.Duration, ok bool)

AsFloodWait returns wait duration and true boolean if err is the "FLOOD_WAIT" error.

Client should wait for that duration before issuing new requests with same method.

func FloodWait added in v0.41.0

func FloodWait(ctx context.Context, err error, opts ...FloodWaitOption) (bool, error)

FloodWait sleeps required duration and returns true if err is FLOOD_WAIT or false and context or original error otherwise.

func Is

func Is(err error, tt ...string) bool

Is returns true if err type is t.

func IsCode

func IsCode(err error, code ...int) bool

IsCode returns true of error code is as provided.

Types

type Error

type Error struct {
	Code     int    // 420
	Message  string // FLOOD_WAIT_3
	Type     string // FLOOD_WAIT
	Argument int    // 3
}

Error represents RPC error returned as result to request.

func As

func As(err error) (rpcErr *Error, ok bool)

As extracts *Error from err if possible.

func AsType

func AsType(err error, t string) (rpcErr *Error, ok bool)

AsType returns *Error from err if rpc error type is t.

func New

func New(code int, msg string) *Error

New creates new *Error from code and message, extracting argument and type.

func (*Error) Error

func (e *Error) Error() string

func (*Error) IsCode

func (e *Error) IsCode(code int) bool

IsCode reports whether error Code is equal to code.

func (*Error) IsCodeOneOf

func (e *Error) IsCodeOneOf(codes ...int) bool

IsCodeOneOf returns true if error code is one of codes.

func (*Error) IsOneOf

func (e *Error) IsOneOf(tt ...string) bool

IsOneOf returns true if error type is in tt.

func (*Error) IsType

func (e *Error) IsType(t string) bool

IsType reports whether error has type t.

type FloodWaitOption added in v0.41.0

type FloodWaitOption interface {
	// contains filtered or unexported methods
}

FloodWaitOption configures flood wait.

func FloodWaitWithClock added in v0.41.0

func FloodWaitWithClock(c clock.Clock) FloodWaitOption

FloodWaitWithClock sets time source for flood wait.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL