{satellite,multinode}/console: fix WriteHeader

w.Header().Set needs to be called before WriteHeader,
because WriteHeader sends all the headers and calls to
Set won't have any effect afterwards.

Change-Id: Ia6b1c5e2cd54201a6c3980d63de04a0095b2db9a
This commit is contained in:
Egon Elbre 2023-05-08 16:53:46 +03:00 committed by Storj Robot
parent 9c753163c2
commit 8beb78ec3f
2 changed files with 3 additions and 3 deletions

View File

@ -29,8 +29,8 @@ func NewNotFound(log *zap.Logger) http.Handler {
// ServeHTTP serves 404 response with json error when resource is not found.
func (handler *NotFound) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusNotFound)
var response struct {
Error string `json:"error"`

View File

@ -845,8 +845,8 @@ func (a *Auth) ResetPassword(w http.ResponseWriter, r *http.Request) {
err = a.service.ResetPassword(ctx, resetPassword.RecoveryToken, resetPassword.NewPassword, resetPassword.MFAPasscode, resetPassword.MFARecoveryCode, time.Now())
if console.ErrMFAMissing.Has(err) || console.ErrMFAPasscode.Has(err) || console.ErrMFARecoveryCode.Has(err) {
w.WriteHeader(a.getStatusCode(err))
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(a.getStatusCode(err))
err = json.NewEncoder(w).Encode(map[string]string{
"error": a.getUserErrorMessage(err),
@ -861,8 +861,8 @@ func (a *Auth) ResetPassword(w http.ResponseWriter, r *http.Request) {
}
if console.ErrTokenExpiration.Has(err) {
w.WriteHeader(a.getStatusCode(err))
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(a.getStatusCode(err))
err = json.NewEncoder(w).Encode(map[string]string{
"error": a.getUserErrorMessage(err),