Fix Message Marshalling for nil data
This commit is contained in:
parent
313257a1ab
commit
24ec424901
2 changed files with 6 additions and 2 deletions
|
@ -10,13 +10,15 @@ import (
|
||||||
|
|
||||||
func respondError(ctx context.Context, c *websocket.Conn, id string, code int64, err error, data any) {
|
func respondError(ctx context.Context, c *websocket.Conn, id string, code int64, err error, data any) {
|
||||||
slog.ErrorContext(ctx, "Responding to Websocket Request With Error", "err", err, "id", id, "code", code, "data", data)
|
slog.ErrorContext(ctx, "Responding to Websocket Request With Error", "err", err, "id", id, "code", code, "data", data)
|
||||||
rData := []byte{}
|
var rData []byte
|
||||||
if data != nil {
|
if data != nil {
|
||||||
rData, err = json.Marshal(data)
|
rData, err = json.Marshal(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.ErrorContext(ctx, "Error Marshalling Error Data", "err", err)
|
slog.ErrorContext(ctx, "Error Marshalling Error Data", "err", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
rData = []byte("\"\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
raw := json.RawMessage(rData)
|
raw := json.RawMessage(rData)
|
||||||
|
|
|
@ -37,7 +37,7 @@ func (s *server) handleRequest(ctx context.Context, c *websocket.Conn, data []by
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rData := json.RawMessage{}
|
var rData json.RawMessage
|
||||||
if data != nil {
|
if data != nil {
|
||||||
rData, err = json.Marshal(result)
|
rData, err = json.Marshal(result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -45,6 +45,8 @@ func (s *server) handleRequest(ctx context.Context, c *websocket.Conn, data []by
|
||||||
slog.ErrorContext(ctx, "Marshalling Response Data", "err", err)
|
slog.ErrorContext(ctx, "Marshalling Response Data", "err", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
rData = []byte("\"\"")
|
||||||
}
|
}
|
||||||
slog.InfoContext(ctx, "response data", "rdata", rData)
|
slog.InfoContext(ctx, "response data", "rdata", rData)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue