File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -50,12 +50,13 @@ func (api CrcApiServer) handleClusterOperations() {
5050
5151func (api CrcApiServer ) handleRequest (req commandRequest , conn net.Conn ) {
5252 defer conn .Close ()
53+ var result string
5354 if handler , ok := api .handlers [req .Command ]; ok {
54- result := handler (req .Args )
55- writeStringToSocket (conn , result )
55+ result = handler (req .Args )
5656 } else {
57- writeStringToSocket ( conn , fmt .Sprintf ("Unknown command supplied: %s" , req .Command ))
57+ result = encodeErrorToJson ( fmt .Sprintf ("Unknown command supplied: %s" , req .Command ))
5858 }
59+ writeStringToSocket (conn , result )
5960}
6061
6162func (api CrcApiServer ) handleConnections (conn net.Conn ) {
@@ -84,7 +85,8 @@ func (api CrcApiServer) handleConnections(conn net.Conn) {
8485 if ! addRequestToChannel (r , api .clusterOpsRequestsChan ) {
8586 defer conn .Close ()
8687 logging .Error ("Channel capacity reached, unable to add new request" )
87- writeStringToSocket (conn , "Channel capacity reached, unable to add new request" )
88+ errMsg := encodeErrorToJson ("Sockets channel capacity reached, unable to add new request" )
89+ writeStringToSocket (conn , errMsg )
8890 return
8991 }
9092 } else {
Original file line number Diff line number Diff line change @@ -80,7 +80,18 @@ func encodeStructToJson(v interface{}) string {
8080 s , err := json .Marshal (v )
8181 if err != nil {
8282 logging .Error (err .Error ())
83- return "Failed"
83+ err := commandError {
84+ Err : "Failed while encoding JSON to string" ,
85+ }
86+ s , _ := json .Marshal (err )
87+ return string (s )
8488 }
8589 return string (s )
8690}
91+
92+ func encodeErrorToJson (errMsg string ) string {
93+ err := commandError {
94+ Err : errMsg ,
95+ }
96+ return encodeStructToJson (err )
97+ }
Original file line number Diff line number Diff line change @@ -7,6 +7,10 @@ import (
77type ArgsType map [string ]string
88type handlerFunc func (ArgsType ) string
99
10+ type commandError struct {
11+ Err string
12+ }
13+
1014type CrcApiServer struct {
1115 listener net.Listener
1216 clusterOpsRequestsChan chan clusterOpsRequest
You can’t perform that action at this time.
0 commit comments