mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-11-24 02:25:21 +00:00
Merge pull request #395 from neilalexander/fix-385
Handle admin socket error cases better
This commit is contained in:
commit
f831f9d2cc
@ -381,11 +381,11 @@ func (a *AdminSocket) handleRequest(conn net.Conn) {
|
|||||||
if r != nil {
|
if r != nil {
|
||||||
send = Info{
|
send = Info{
|
||||||
"status": "error",
|
"status": "error",
|
||||||
"error": "Unrecoverable error, possibly as a result of invalid input types or malformed syntax",
|
"error": "Check your syntax and input types",
|
||||||
}
|
}
|
||||||
a.log.Errorln("Admin socket error:", r)
|
a.log.Debugln("Admin socket error:", r)
|
||||||
if err := encoder.Encode(&send); err != nil {
|
if err := encoder.Encode(&send); err != nil {
|
||||||
a.log.Errorln("Admin socket JSON encode error:", err)
|
a.log.Debugln("Admin socket JSON encode error:", err)
|
||||||
}
|
}
|
||||||
conn.Close()
|
conn.Close()
|
||||||
}
|
}
|
||||||
@ -407,13 +407,14 @@ func (a *AdminSocket) handleRequest(conn net.Conn) {
|
|||||||
send["request"] = recv
|
send["request"] = recv
|
||||||
send["status"] = "error"
|
send["status"] = "error"
|
||||||
|
|
||||||
|
n := strings.ToLower(recv["request"].(string))
|
||||||
|
|
||||||
if _, ok := recv["request"]; !ok {
|
if _, ok := recv["request"]; !ok {
|
||||||
send["error"] = "No request sent"
|
send["error"] = "No request sent"
|
||||||
break
|
goto respond
|
||||||
}
|
}
|
||||||
|
|
||||||
n := strings.ToLower(recv["request"].(string))
|
if h, ok := a.handlers[n]; ok {
|
||||||
if h, ok := a.handlers[strings.ToLower(n)]; ok {
|
|
||||||
// Check that we have all the required arguments
|
// Check that we have all the required arguments
|
||||||
for _, arg := range h.args {
|
for _, arg := range h.args {
|
||||||
// An argument in [square brackets] is optional and not required,
|
// An argument in [square brackets] is optional and not required,
|
||||||
@ -428,7 +429,7 @@ func (a *AdminSocket) handleRequest(conn net.Conn) {
|
|||||||
"error": "Expected field missing: " + arg,
|
"error": "Expected field missing: " + arg,
|
||||||
"expecting": arg,
|
"expecting": arg,
|
||||||
}
|
}
|
||||||
break
|
goto respond
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -439,16 +440,28 @@ func (a *AdminSocket) handleRequest(conn net.Conn) {
|
|||||||
send["error"] = err.Error()
|
send["error"] = err.Error()
|
||||||
if response != nil {
|
if response != nil {
|
||||||
send["response"] = response
|
send["response"] = response
|
||||||
|
goto respond
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
send["status"] = "success"
|
send["status"] = "success"
|
||||||
if response != nil {
|
if response != nil {
|
||||||
send["response"] = response
|
send["response"] = response
|
||||||
|
goto respond
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Start with a clean response on each request, which defaults to an error
|
||||||
|
// state. If a handler is found below then this will be overwritten
|
||||||
|
send = Info{
|
||||||
|
"request": recv,
|
||||||
|
"status": "error",
|
||||||
|
"error": fmt.Sprintf("Unknown action '%s', try 'list' for help", recv["request"].(string)),
|
||||||
|
}
|
||||||
|
goto respond
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the response back
|
// Send the response back
|
||||||
|
respond:
|
||||||
if err := encoder.Encode(&send); err != nil {
|
if err := encoder.Encode(&send); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user