diff --git a/common/database/mongo_database.go b/common/database/mongo_database.go index 223d9df3..7a45b90a 100644 --- a/common/database/mongo_database.go +++ b/common/database/mongo_database.go @@ -44,13 +44,13 @@ func (db *MongoDatabase) Connect(host string) error { return ErrConnection } + dial_info.Timeout = 60 * time.Second if config.IS_PRODUCTION { dial_info.DialServer = func(addr *mgo.ServerAddr) (net.Conn, error) { tls_config := &tls.Config{} connection, err := tls.Dial("tcp", addr.String(), tls_config) return connection, err } - dial_info.Timeout = 60 * time.Second } session, err := mgo.DialWithInfo(dial_info) diff --git a/common/errors/DatabaseError.go b/common/errors/DatabaseError.go index 7d032b1a..e6cc910e 100644 --- a/common/errors/DatabaseError.go +++ b/common/errors/DatabaseError.go @@ -1,8 +1,17 @@ package errors -import "net/http" +import ( + "net/http" +) + +const MONGO_NOT_FOUND_ERR = "Error: NOT_FOUND" // An error that occurs when a database operation (e.g. fetch / insert / update) doesn't work. func DatabaseError(raw_error string, message string) ApiError { - return ApiError{Status: http.StatusInternalServerError, Type: "DATABASE_ERROR", Message: message, RawError: raw_error} + http_status_error := http.StatusInternalServerError + if raw_error == MONGO_NOT_FOUND_ERR { + http_status_error = http.StatusNotFound + } + + return ApiError{Status: http_status_error, Type: "DATABASE_ERROR", Message: message, RawError: raw_error} } diff --git a/services/project/main.go b/services/project/main.go index cb127762..5b12881f 100644 --- a/services/project/main.go +++ b/services/project/main.go @@ -1,12 +1,13 @@ package project import ( + "log" + "github.com/HackIllinois/api/common/apiserver" "github.com/HackIllinois/api/services/project/config" "github.com/HackIllinois/api/services/project/controller" "github.com/HackIllinois/api/services/project/service" "github.com/gorilla/mux" - "log" ) func Initialize() error {