Add logging error messages

This commit is contained in:
Melon 2023-09-11 17:49:44 +01:00
parent 2918a32c1c
commit f90abb3d74
Signed by: melon
GPG Key ID: 6C9D970C50D26A25

View File

@ -58,19 +58,21 @@ func SetupApiServer(listen string, auth *AuthChecker, send Smtp, recv Imap) *htt
dec.DisallowUnknownFields() dec.DisallowUnknownFields()
err = dec.Decode(&tokenMsg) err = dec.Decode(&tokenMsg)
if err != nil { if err != nil {
_ = c.WriteJSON(map[string]string{"error": "Authentication missing"})
return return
} }
// get a "possible" auth token value // get a "possible" auth token value
// exit on empty token value // exit on empty token value
if tokenMsg.Token == "" { if tokenMsg.Token == "" {
_ = c.WriteJSON(map[string]string{"error": "Authentication missing"})
return return
} }
// check the token // check the token
authUser, err := auth.Check(tokenMsg.Token) authUser, err := auth.Check(tokenMsg.Token)
if err != nil { if err != nil {
// exit on error _ = c.WriteJSON(map[string]string{"error": "Authentication invalid"})
return return
} }
@ -101,21 +103,21 @@ func SetupApiServer(listen string, auth *AuthChecker, send Smtp, recv Imap) *htt
} }
err := c.ReadJSON(&m) err := c.ReadJSON(&m)
if err != nil { if err != nil {
// errors should close the connection _ = c.WriteJSON(map[string]string{"error": "Invalid input"})
return return
} }
// handle action // handle action
j, err := client.HandleWS(m.Action, m.Args) j, err := client.HandleWS(m.Action, m.Args)
if err != nil { if err != nil {
// errors should close the connection _ = c.WriteJSON(map[string]string{"error": "Action failed"})
return return
} }
// write outgoing message // write outgoing message
err = c.WriteJSON(j) err = c.WriteJSON(j)
if err != nil { if err != nil {
// errors should close the connection _ = c.WriteJSON(map[string]string{"error": "Invalid output"})
return return
} }
} }