cluade code review changes
This commit is contained in:
@@ -59,10 +59,12 @@ func reply(w http.ResponseWriter, data any, p *request.Pager) {
|
||||
|
||||
// json data...
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(Detail{
|
||||
if err := json.NewEncoder(w).Encode(Detail{
|
||||
Data: data,
|
||||
Pager: p,
|
||||
})
|
||||
}); err != nil {
|
||||
slog.Error(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func BadRequest(w http.ResponseWriter, err error) {
|
||||
@@ -92,9 +94,14 @@ func SessionExpired(w http.ResponseWriter) {
|
||||
}
|
||||
}
|
||||
|
||||
// Deprecated: Use NotAuthorized instead.
|
||||
func NotAutorized(w http.ResponseWriter) {
|
||||
NotAuthorized(w)
|
||||
}
|
||||
|
||||
func NotAuthorized(w http.ResponseWriter) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
_, writeErr := fmt.Fprint(w, "{\"error\": \"You are not authorized to perform this action\"}")
|
||||
if writeErr != nil {
|
||||
slog.Error(writeErr.Error())
|
||||
|
||||
Reference in New Issue
Block a user