mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
fix(onboarding): could not create user (#848)
fix: onboarding not working
This commit is contained in:
parent
d03561d61c
commit
7f05dd1efd
16 changed files with 182 additions and 130 deletions
|
@ -1,7 +1,6 @@
|
|||
package http
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
@ -13,7 +12,12 @@ type errorResponse struct {
|
|||
Status int `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
func (e encoder) StatusResponse(ctx context.Context, w http.ResponseWriter, response interface{}, status int) {
|
||||
type statusResponse struct {
|
||||
Message string `json:"message"`
|
||||
Status int `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
func (e encoder) StatusResponse(w http.ResponseWriter, status int, response interface{}) {
|
||||
if response != nil {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(status)
|
||||
|
@ -26,6 +30,19 @@ func (e encoder) StatusResponse(ctx context.Context, w http.ResponseWriter, resp
|
|||
}
|
||||
}
|
||||
|
||||
func (e encoder) StatusResponseMessage(w http.ResponseWriter, status int, message string) {
|
||||
if message != "" {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(status)
|
||||
if err := json.NewEncoder(w).Encode(statusResponse{Message: message}); err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
w.WriteHeader(status)
|
||||
}
|
||||
}
|
||||
|
||||
func (e encoder) StatusCreated(w http.ResponseWriter) {
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
}
|
||||
|
@ -43,7 +60,7 @@ func (e encoder) NoContent(w http.ResponseWriter) {
|
|||
w.WriteHeader(http.StatusNoContent)
|
||||
}
|
||||
|
||||
func (e encoder) StatusNotFound(ctx context.Context, w http.ResponseWriter) {
|
||||
func (e encoder) StatusNotFound(w http.ResponseWriter) {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
}
|
||||
|
||||
|
@ -60,3 +77,16 @@ func (e encoder) Error(w http.ResponseWriter, err error) {
|
|||
w.WriteHeader(http.StatusInternalServerError)
|
||||
json.NewEncoder(w).Encode(res)
|
||||
}
|
||||
|
||||
func (e encoder) StatusError(w http.ResponseWriter, status int, err error) {
|
||||
res := errorResponse{
|
||||
Message: err.Error(),
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(status)
|
||||
if err := json.NewEncoder(w).Encode(res); err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue