diff options
author | Keuin <[email protected]> | 2023-07-02 16:12:13 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2023-07-02 16:12:13 +0800 |
commit | 76a7674dae069e0be15bed6af8450ad214f8dde2 (patch) | |
tree | 5b0f1b09ce3c212c5dcc88d53667421cd3d5ac9d /recording/watcher.go | |
parent | 6f7987593a9db5500fa56fef0ec1845a02df9876 (diff) |
Refactor: distinct task errors with type enum.
Diffstat (limited to 'recording/watcher.go')
-rw-r--r-- | recording/watcher.go | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/recording/watcher.go b/recording/watcher.go index dd3bfa8..181e0fc 100644 --- a/recording/watcher.go +++ b/recording/watcher.go @@ -3,7 +3,7 @@ package recording import ( "context" "encoding/json" - "github.com/keuin/slbr/bilibili/errors" + errs "github.com/keuin/slbr/bilibili/errors" "github.com/keuin/slbr/danmaku" "github.com/keuin/slbr/danmaku/dmmsg" "github.com/keuin/slbr/danmaku/dmpkg" @@ -51,7 +51,7 @@ func watch( // connect to danmaku server for live online/offline notifications err = dm.Connect(ctx, url) if err != nil { - return errors.NewRecoverableTaskError("failed to connect to danmaku server", err) + return errs.NewError(errs.DanmakuServerConnection, err) } defer func() { // this operation may be time-consuming, so run in another goroutine @@ -64,7 +64,7 @@ func watch( logger.Info("ws connected. Authenticating...") err = dm.Authenticate(t.RoomId, authKey) if err != nil { - return errors.NewUnrecoverableTaskError("authentication failed, invalid protocol", err) + return errs.NewError(errs.InvalidAuthProtocol, err) } // the danmaku server requires heartbeat messages every 30 seconds @@ -76,7 +76,7 @@ func watch( // send initial heartbeat immediately err = heartbeat() if err != nil { - return errors.NewRecoverableTaskError("heartbeat failed", err) + return errs.NewError(errs.Heartbeat, err) } // create heartbeat timer @@ -86,7 +86,7 @@ func watch( logger.Info("Checking initial live status...") isLiving, err := AutoRetryWithConfig[bool](ctx, logger, &t, liveStatusChecker) if err != nil { - return errors.NewRecoverableTaskError("check initial live status failed", err) + return errs.NewError(errs.InitialLiveStatus, err) } if isLiving { logger.Info("The live is already started. Start recording immediately.") @@ -102,18 +102,18 @@ func watch( case <-heartBeatTimer.C: err = heartbeat() if err != nil { - return errors.NewRecoverableTaskError("heartbeat failed", err) + return errs.NewError(errs.Heartbeat, err) } default: var msg dmpkg.DanmakuExchange msg, err = dm.ReadExchange() if err != nil { - return errors.NewRecoverableTaskError("failed to read exchange from server", err) + return errs.NewError(errs.DanmakuExchangeRead, err) } // the exchange may be compressed msg, err = msg.Inflate() if err != nil { - return errors.NewUnrecoverableTaskError("failed to decompress server message", err) + return errs.NewError(errs.MessageDecompression, err) } switch msg.Operation { @@ -123,7 +123,7 @@ func watch( err := json.Unmarshal(msg.Body, &info) if err != nil { logger.Error("Invalid JSON: \"%v\", exchange: %v", string(msg.Body), msg) - return errors.NewUnrecoverableTaskError("invalid JSON response from server", err) + return errs.NewError(errs.JsonDecode, err) } switch info.Command { case CommandLiveStart: |