[PD1] Error handling project-wide
This commit is contained in:
parent
f5b3726673
commit
b918211736
13 changed files with 364 additions and 245 deletions
|
@ -1,7 +1,7 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"log"
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -14,33 +14,34 @@ type ClientMessage struct {
|
|||
}
|
||||
|
||||
type ClientMessageInfo struct {
|
||||
Num int
|
||||
FromUID string
|
||||
Timestamp time.Time
|
||||
Subject string
|
||||
Num int
|
||||
FromUID string
|
||||
Timestamp time.Time
|
||||
Subject string
|
||||
decryptError error
|
||||
}
|
||||
|
||||
func newClientMessage(fromUID string, toUID string, subject string, body string, timestamp time.Time) ClientMessage {
|
||||
return ClientMessage{FromUID: fromUID, ToUID: toUID, Subject: subject, Body: body, Timestamp: timestamp}
|
||||
}
|
||||
|
||||
func newClientMessageInfo(num int, fromUID string, subject string, timestamp time.Time) ClientMessageInfo {
|
||||
return ClientMessageInfo{Num:num,FromUID: fromUID,Subject: subject,Timestamp: timestamp}
|
||||
func newClientMessageInfo(num int, fromUID string, subject string, timestamp time.Time, err error) ClientMessageInfo {
|
||||
return ClientMessageInfo{Num: num, FromUID: fromUID, Subject: subject, Timestamp: timestamp, decryptError: err}
|
||||
}
|
||||
|
||||
func Marshal(data any) []byte {
|
||||
func Marshal(data any) ([]byte, error) {
|
||||
subject, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
log.Panicf("Error when marshalling message: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
return subject
|
||||
return subject, nil
|
||||
}
|
||||
|
||||
func Unmarshal(data []byte) string {
|
||||
func Unmarshal(data []byte) (string, error) {
|
||||
var c string
|
||||
err := json.Unmarshal(data, &c)
|
||||
if err != nil {
|
||||
log.Panicln("Could not unmarshal data")
|
||||
return "", err
|
||||
}
|
||||
return c
|
||||
return c, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue