处理错误
This commit is contained in:
		@@ -42,12 +42,15 @@ func ModelsPost(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
		var model models.Model
 | 
			
		||||
		body, err := ioutil.ReadAll(r.Body)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Println(err)
 | 
			
		||||
			w.WriteHeader(http.StatusBadRequest)
 | 
			
		||||
			w.Write([]byte(err.Error()))
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
		defer r.Body.Close()
 | 
			
		||||
 | 
			
		||||
		if err = json.Unmarshal(body, &model); err != nil {
 | 
			
		||||
			log.Println(err)
 | 
			
		||||
			w.WriteHeader(http.StatusBadRequest)
 | 
			
		||||
			w.Write([]byte(err.Error()))
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user