Skip to content

Commit

Permalink
feat: added IsDataNotFound
Browse files Browse the repository at this point in the history
chore: cleanup
  • Loading branch information
jfk9w committed Jun 20, 2024
1 parent 7dbf00c commit abdc91e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
12 changes: 5 additions & 7 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net/http"
"time"

"github.com/AlekSi/pointer"
"github.com/jfk9w-go/based"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -74,11 +73,11 @@ type Client struct {
}

func (c *Client) Receipt(ctx context.Context, in *ReceiptIn) (*ReceiptOut, error) {
return execute[ReceiptOut](ctx, c, in)
return execute(ctx, c, in)
}

func (c *Client) FiscalData(ctx context.Context, in *FiscalDataIn) (*FiscalDataOut, error) {
return execute[FiscalDataOut](ctx, c, in)
return execute(ctx, c, in)
}

func (c *Client) ensureToken(ctx context.Context) (string, error) {
Expand All @@ -89,8 +88,7 @@ func (c *Client) ensureToken(ctx context.Context) (string, error) {

now := c.clock.Now()
updateToken := true
if tokens == nil || tokens.RefreshTokenExpiresIn != nil &&
pointer.Get[DateTimeTZ](tokens.RefreshTokenExpiresIn).Time().Before(now.Add(expireTokenOffset)) {
if tokens == nil || tokens.RefreshTokenExpiresIn != nil && tokens.RefreshTokenExpiresIn.Time().Before(now.Add(expireTokenOffset)) {
tokens, err = c.authorize(ctx)
if err != nil {
return "", errors.Wrap(err, "authorize")
Expand Down Expand Up @@ -130,7 +128,7 @@ func (c *Client) authorize(ctx context.Context) (*Tokens, error) {
CaptchaToken: captchaToken,
}

startOut, err := execute[startOut](ctx, c, startIn)
startOut, err := execute(ctx, c, startIn)
if err != nil {
var clientErr Error
if !errors.As(err, &clientErr) || clientErr.Code != SmsVerificationNotExpired {
Expand All @@ -150,7 +148,7 @@ func (c *Client) authorize(ctx context.Context) (*Tokens, error) {
Code: code,
}

tokens, err := execute[Tokens](ctx, c, verifyIn)
tokens, err := execute(ctx, c, verifyIn)
if err != nil {
return nil, errors.Wrap(err, "verify code")
}
Expand Down
10 changes: 10 additions & 0 deletions dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ type ErrorCode string
const (
SmsVerificationNotExpired ErrorCode = "registration.sms.verification.not.expired"
BlockedCaptcha ErrorCode = "blocked.captcha"
ReceiptFiscalDataNotFound ErrorCode = "receipt.fiscaldata.not.found.dr"
)

type Error struct {
Expand All @@ -179,6 +180,15 @@ func (e Error) Error() string {
return b.String()
}

func IsDataNotFound(err error) bool {
var e Error
if errors.Is(err, &e); e.Code == ReceiptFiscalDataNotFound {
return true
}

return false
}

type metaDetails struct {
UserAgent string `json:"userAgent"`
}
Expand Down

0 comments on commit abdc91e

Please sign in to comment.