Fix bad JSON style
This commit is contained in:
parent
3aafb15f19
commit
e30afad3d2
1 changed files with 9 additions and 9 deletions
|
@ -20,10 +20,10 @@ func (SubmissionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
// Check request type and size
|
||||
if r.Method != "POST" {
|
||||
http.Error(w, "{errmsg:\"Bad request.\"}", http.StatusBadRequest)
|
||||
http.Error(w, "{\"errmsg\":\"Bad request.\"}", http.StatusBadRequest)
|
||||
return
|
||||
} else if r.ContentLength < 0 || r.ContentLength > 255 {
|
||||
http.Error(w, "{errmsg:\"Request too large or request size unknown\"}", http.StatusRequestEntityTooLarge)
|
||||
http.Error(w, "{\"errmsg\":\"Request too large or request size unknown\"}", http.StatusRequestEntityTooLarge)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -32,23 +32,23 @@ func (SubmissionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
var sURL = strings.Split(r.URL.Path, "/")
|
||||
|
||||
if len(sURL) != 3 && len(sURL) != 4 {
|
||||
http.Error(w, "{errmsg:\"Bad request.\"}", http.StatusBadRequest)
|
||||
http.Error(w, "{\"errmsg\":\"Bad request.\"}", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Parse arguments
|
||||
if team, err := strconv.Atoi(sURL[1]); err != nil {
|
||||
http.Error(w, "{errmsg:\"Bad request.\"}", http.StatusBadRequest)
|
||||
http.Error(w, "{\"errmsg\":\"Bad request.\"}", http.StatusBadRequest)
|
||||
return
|
||||
} else if exercice, err := strconv.Atoi(sURL[2]); err != nil {
|
||||
http.Error(w, "{errmsg:\"Bad request.\"}", http.StatusBadRequest)
|
||||
http.Error(w, "{\"errmsg\":\"Bad request.\"}", http.StatusBadRequest)
|
||||
return
|
||||
} else {
|
||||
if _, err := os.Stat(path.Join(SubmissionDir, fmt.Sprintf("%d", team))); os.IsNotExist(err) {
|
||||
log.Println("Creating submission directory for", team)
|
||||
if err := os.MkdirAll(path.Join(SubmissionDir, fmt.Sprintf("%d", team)), 0777); err != nil {
|
||||
log.Println("Unable to create submission directory: ", err)
|
||||
http.Error(w, "{errmsg:\"Internal server error. Please retry in few seconds.\"}", http.StatusInternalServerError)
|
||||
http.Error(w, "{\"errmsg\":\"Internal server error. Please retry in few seconds.\"}", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ func (SubmissionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
// Previous submission not treated
|
||||
if _, err := os.Stat(path.Join(SubmissionDir, fmt.Sprintf("%d", team), fmt.Sprintf("%d", exercice))); !os.IsNotExist(err) {
|
||||
http.Error(w, "{errmsg:\"Calm-down. A solution is already being processed.\"}", http.StatusPaymentRequired)
|
||||
http.Error(w, "{\"errmsg\":\"Calm-down. A solution is already being processed.\"}", http.StatusPaymentRequired)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -80,12 +80,12 @@ func (SubmissionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
// Store content in file
|
||||
if file, err := os.Create(path.Join(SubmissionDir, fmt.Sprintf("%d", team), fmt.Sprintf("%d", exercice))); err != nil {
|
||||
log.Println("Unable to open exercice file:", err)
|
||||
http.Error(w, "{errmsg:\"Internal server error. Please retry in few seconds.\"}", http.StatusInternalServerError)
|
||||
http.Error(w, "{\"errmsg\":\"Internal server error. Please retry in few seconds.\"}", http.StatusInternalServerError)
|
||||
return
|
||||
} else {
|
||||
file.Write(body)
|
||||
file.Close()
|
||||
}
|
||||
http.Error(w, "{errmsg:\"Submission accepted, please wait...\"}", http.StatusAccepted)
|
||||
http.Error(w, "{\"errmsg\":\"Submission accepted, please wait...\"}", http.StatusAccepted)
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue