refactor(handlers): Use fmt.Errorf instead of errors.New(fmt.Sprintf())
This commit is contained in:
parent
74fbef4ae8
commit
e714cca477
1 changed files with 2 additions and 3 deletions
|
|
@ -1,7 +1,6 @@
|
||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -20,14 +19,14 @@ func updateEndpointValidator(
|
||||||
if !ok || !util.CheckCredentials(authDB, validCredentials, username, password) {
|
if !ok || !util.CheckCredentials(authDB, validCredentials, username, password) {
|
||||||
w.Header().Set("WWW-Authenticate", "Basic realm=\"spaceapid\"")
|
w.Header().Set("WWW-Authenticate", "Basic realm=\"spaceapid\"")
|
||||||
http.Error(w, "", http.StatusUnauthorized)
|
http.Error(w, "", http.StatusUnauthorized)
|
||||||
return []byte{}, errors.New(fmt.Sprintf("Unauthorized request from %s Username: %s Password: %s", r.RemoteAddr, username, password))
|
return []byte{}, fmt.Errorf("Unauthorized request from %s Username: %s Password: %s", r.RemoteAddr, username, password)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read request body
|
// Read request body
|
||||||
body, err := io.ReadAll(r.Body)
|
body, err := io.ReadAll(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "", http.StatusInternalServerError)
|
http.Error(w, "", http.StatusInternalServerError)
|
||||||
return []byte{}, errors.New(fmt.Sprintf("Failed to read request body from %s with error: %s", r.RemoteAddr, err))
|
return []byte{}, fmt.Errorf("Failed to read request body from %s with error: %s", r.RemoteAddr, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return body, nil
|
return body, nil
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue