user, err := module.Configure.Repositories.UserRepository.FindByID(id) // データがない時のエラー if err == gorm.ErrRecordNotFound { c.JSON(http.StatusNotFound, gin.H{"error": fmt.Sprintf("reservation number not found")}) return } // その他のエラー if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return }
err == gorm.ErrRecordNotFound
の時は http.StatusNotFound
http.StatusInternalServerError
http.StatusBadRequest
http.StatusNotFound 404 // 欲しいデータが見つからない。 http.StatusBadRequest 400 // リクエストがおかしい type reqParams struct { user_id uint64 } なのにstring でパラメーターを送ってしまったとか。 http.StatusInternalServerError 500 // サーバーと接続ができない //サーバーがダウンしているなど。