Skip to content

Commit

Permalink
make writeError generic
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Feb 27, 2025
1 parent fe8992c commit fcb6d5b
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,7 @@ func (s *submitServer) handleSubmission(w http.ResponseWriter, req *http.Request
log.Printf("Unable to remove report dir %s after rejected upload: %v\n",
reportDir, err)
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(400)
json.NewEncoder(w).Encode(submitPolicyErrorResponse{"This server does not accept rageshakes from your application.", "RS_DISALLOWED_APP", "https://github.com/matrix-org/rageshake/blob/master/docs/blocked_rageshake.md"})
writeError(w, 400, submitPolicyErrorResponse{"This server does not accept rageshakes from your application.", "RS_DISALLOWED_APP", "https://github.com/matrix-org/rageshake/blob/master/docs/blocked_rageshake.md"})
return
}
rejection, code := s.cfg.matchesRejectionCondition(p)
Expand All @@ -248,9 +246,7 @@ func (s *submitServer) handleSubmission(w http.ResponseWriter, req *http.Request
reportDir, err)
}
userErrorText := fmt.Sprintf("This server did not accept the rageshake because it matches a rejection condition: %s.", *rejection)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(400)
json.NewEncoder(w).Encode(submitPolicyErrorResponse{userErrorText, *code, "https://github.com/matrix-org/rageshake/blob/master/docs/blocked_rageshake.md"})
writeError(w, 400, submitPolicyErrorResponse{userErrorText, *code, "https://github.com/matrix-org/rageshake/blob/master/docs/blocked_rageshake.md"})
return
}

Expand All @@ -271,7 +267,7 @@ func (s *submitServer) handleSubmission(w http.ResponseWriter, req *http.Request
json.NewEncoder(w).Encode(resp)
}

func writeError(w http.ResponseWriter, status int, response submitErrorResponse) {
func writeError(w http.ResponseWriter, status int, response interface{}) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
json.NewEncoder(w).Encode(response)
Expand Down

0 comments on commit fcb6d5b

Please sign in to comment.