mirror of
https://github.com/1f349/lotus.git
synced 2024-12-22 16:14:07 +00:00
Add logging error messages
This commit is contained in:
parent
2918a32c1c
commit
f90abb3d74
10
api/api.go
10
api/api.go
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user