mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-22 00:21:55 +00:00
Daniel Mason
fd615102a8
- Fixed looking up invalid profiles - Added valid error handling to bad request && rate limiting - Add Sendgrid library (Will add SMTP later) - Complete password reset process
59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
package goscrobble
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"net/http"
|
|
)
|
|
|
|
// MIDDLEWARE RESPONSES
|
|
// throwUnauthorized - Throws a 403
|
|
func throwUnauthorized(w http.ResponseWriter, m string) {
|
|
jr := jsonResponse{
|
|
Err: m,
|
|
}
|
|
js, _ := json.Marshal(&jr)
|
|
err := errors.New(string(js))
|
|
http.Error(w, err.Error(), http.StatusUnauthorized)
|
|
}
|
|
|
|
// throwUnauthorized - Throws a 403
|
|
func throwBadReq(w http.ResponseWriter, m string) {
|
|
jr := jsonResponse{
|
|
Err: m,
|
|
}
|
|
js, _ := json.Marshal(&jr)
|
|
err := errors.New(string(js))
|
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
}
|
|
|
|
// throwOkError - Throws a 403
|
|
func throwOkError(w http.ResponseWriter, m string) {
|
|
jr := jsonResponse{
|
|
Err: m,
|
|
}
|
|
js, _ := json.Marshal(&jr)
|
|
w.WriteHeader(http.StatusOK)
|
|
w.Write(js)
|
|
}
|
|
|
|
// throwOkMessage - Throws a happy 200
|
|
func throwOkMessage(w http.ResponseWriter, m string) {
|
|
jr := jsonResponse{
|
|
Msg: m,
|
|
}
|
|
js, _ := json.Marshal(&jr)
|
|
w.WriteHeader(http.StatusOK)
|
|
w.Write(js)
|
|
}
|
|
|
|
// throwOkMessage - Throws a happy 200
|
|
func throwInvalidJson(w http.ResponseWriter) {
|
|
jr := jsonResponse{
|
|
Err: "Invalid JSON",
|
|
}
|
|
js, _ := json.Marshal(&jr)
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
w.Write(js)
|
|
}
|