fix(onboarding): could not create user (#848)

fix: onboarding not working
This commit is contained in:
ze0s 2023-04-17 20:56:17 +02:00 committed by GitHub
parent d03561d61c
commit 7f05dd1efd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 182 additions and 130 deletions

View file

@ -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
}
}