removed obsolete errors
This commit is contained in:
@@ -2,12 +2,12 @@ package notificationimp
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/tech/sendico/notification/interface/api"
|
||||
mmail "github.com/tech/sendico/notification/internal/server/notificationimp/mail"
|
||||
"github.com/tech/sendico/notification/internal/server/notificationimp/telegram"
|
||||
"github.com/tech/sendico/pkg/domainprovider"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
na "github.com/tech/sendico/pkg/messaging/notifications/account"
|
||||
ni "github.com/tech/sendico/pkg/messaging/notifications/invitation"
|
||||
snotifications "github.com/tech/sendico/pkg/messaging/notifications/site"
|
||||
@@ -39,10 +39,10 @@ func CreateAPI(a api.API) (*NotificationAPI, error) {
|
||||
p.logger = a.Logger().Named(p.Name())
|
||||
|
||||
if a.Config().Notification == nil {
|
||||
return nil, fmt.Errorf("notification configuration is missing")
|
||||
return nil, merrors.InvalidArgument("notification configuration is missing")
|
||||
}
|
||||
if a.Config().Notification.Telegram == nil {
|
||||
return nil, fmt.Errorf("telegram configuration is missing")
|
||||
return nil, merrors.InvalidArgument("telegram configuration is missing")
|
||||
}
|
||||
|
||||
var err error
|
||||
@@ -90,7 +90,7 @@ func CreateAPI(a api.API) (*NotificationAPI, error) {
|
||||
|
||||
func (a *NotificationAPI) onDemoRequest(ctx context.Context, request *model.DemoRequest) error {
|
||||
if a.tg == nil {
|
||||
return fmt.Errorf("telegram client is not configured")
|
||||
return merrors.Internal("telegram client is not configured")
|
||||
}
|
||||
if err := a.tg.SendDemoRequest(ctx, request); err != nil {
|
||||
a.logger.Warn("Failed to send demo request via telegram", zap.Error(err))
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"time"
|
||||
|
||||
notconfig "github.com/tech/sendico/notification/interface/services/notification/config"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
)
|
||||
@@ -45,15 +46,15 @@ type sendMessagePayload struct {
|
||||
|
||||
func NewClient(logger mlogger.Logger, cfg *notconfig.TelegramConfig) (Client, error) {
|
||||
if cfg == nil {
|
||||
return nil, fmt.Errorf("telegram configuration is not provided")
|
||||
return nil, merrors.InvalidArgument("telegram configuration is not provided")
|
||||
}
|
||||
token := strings.TrimSpace(os.Getenv(cfg.BotTokenEnv))
|
||||
if token == "" {
|
||||
return nil, fmt.Errorf("telegram bot token env %s is empty", cfg.BotTokenEnv)
|
||||
return nil, merrors.InvalidArgument(fmt.Sprintf("telegram bot token env %s is empty", cfg.BotTokenEnv))
|
||||
}
|
||||
chatID := strings.TrimSpace(os.Getenv(cfg.ChatIDEnv))
|
||||
if chatID == "" {
|
||||
return nil, fmt.Errorf("telegram chat id env %s is empty", cfg.ChatIDEnv)
|
||||
return nil, merrors.InvalidArgument(fmt.Sprintf("telegram chat id env %s is empty", cfg.ChatIDEnv))
|
||||
}
|
||||
|
||||
var threadID *int64
|
||||
@@ -62,7 +63,7 @@ func NewClient(logger mlogger.Logger, cfg *notconfig.TelegramConfig) (Client, er
|
||||
if raw != "" {
|
||||
val, err := strconv.ParseInt(raw, 10, 64)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("telegram thread id env %s is invalid: %w", env, err)
|
||||
return nil, merrors.InvalidArgumentWrap(err, fmt.Sprintf("telegram thread id env %s is invalid", env))
|
||||
}
|
||||
threadID = &val
|
||||
}
|
||||
@@ -93,7 +94,7 @@ func NewClient(logger mlogger.Logger, cfg *notconfig.TelegramConfig) (Client, er
|
||||
|
||||
func (c *client) SendDemoRequest(ctx context.Context, request *model.DemoRequest) error {
|
||||
if request == nil {
|
||||
return fmt.Errorf("demo request payload is nil")
|
||||
return merrors.InvalidArgument("demo request payload is nil")
|
||||
}
|
||||
message := buildMessage(request)
|
||||
payload := sendMessagePayload{
|
||||
@@ -127,7 +128,7 @@ func (c *client) sendMessage(ctx context.Context, payload sendMessagePayload) er
|
||||
return nil
|
||||
}
|
||||
respBody, _ := io.ReadAll(io.LimitReader(resp.Body, 4<<10))
|
||||
return fmt.Errorf("telegram sendMessage failed with status %d: %s", resp.StatusCode, string(respBody))
|
||||
return merrors.Internal(fmt.Sprintf("telegram sendMessage failed with status %d: %s", resp.StatusCode, string(respBody)))
|
||||
}
|
||||
|
||||
func (c *client) endpoint() string {
|
||||
|
||||
Reference in New Issue
Block a user