Skip to content

Commit

Permalink
chore: improve error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
damonto committed Mar 31, 2024
1 parent 9be6c76 commit fe86d7f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions internal/rlpa/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (c *Conn) registerHandlers() {
conn.Send(TagMessageBox, []byte("Processing notifications..."))
if err := processNotification(conn); err != nil {
slog.Error("error processing notification", "error", err)
return conn.Send(TagMessageBox, []byte("Process failed \n"+err.Error()))
return conn.Send(TagMessageBox, []byte("Process failed \n"+ToTitle(err.Error())))
}
return conn.Send(TagMessageBox, []byte("All notifications have been processed successfully"))
},
Expand All @@ -50,7 +50,7 @@ func (c *Conn) registerHandlers() {
conn.Send(TagMessageBox, []byte("Your profile is being downloaded. \n Please wait..."))
if err := downloadProfile(conn, data); err != nil {
slog.Error("error downloading profile", "error", err)
return conn.Send(TagMessageBox, []byte("Download failed \n"+err.Error()))
return conn.Send(TagMessageBox, []byte("Download failed \n"+ToTitle(err.Error())))
}
return conn.Send(TagMessageBox, []byte("Your profile has been downloaded successfully"))
},
Expand Down
4 changes: 2 additions & 2 deletions internal/rlpa/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

const (
ErrInvalidActivationCode = "invalid activation code"
ErrRequireConfirmationCode = "replace <cc> with a confirmation code and try again\n"
ErrRequireConfirmationCode = "confirmation code is required\n"
)

func downloadProfile(conn *Conn, data []byte) error {
Expand All @@ -36,7 +36,7 @@ func downloadProfile(conn *Conn, data []byte) error {
if len(parts) == 5 {
confirmationCode = string(parts[4])
if confirmationCode == "1" {
parts[4] = []byte("<cc>")
parts[4] = bytes.Replace([]byte("<confirmation_code>"), []byte("_"), []byte{0x11}, 1)
return errors.New(ErrRequireConfirmationCode + string(bytes.Join(parts, []byte{0x02})))
}
}
Expand Down
8 changes: 8 additions & 0 deletions internal/rlpa/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package rlpa

import "unicode"

func ToTitle(s string) string {
r := []rune(s)
return string(unicode.ToUpper(r[0])) + string(r[1:])
}

0 comments on commit fe86d7f

Please sign in to comment.