mirror of
				https://github.com/simon987/task_tracker.git
				synced 2025-11-04 09:46:52 +00:00 
			
		
		
		
	Some error handling work
This commit is contained in:
		
							parent
							
								
									0ea6e18fb9
								
							
						
					
					
						commit
						15c4090a94
					
				
							
								
								
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@ -1,2 +1,3 @@
 | 
				
			|||||||
.idea/
 | 
					.idea/
 | 
				
			||||||
*.iml
 | 
					*.iml
 | 
				
			||||||
 | 
					log.txt
 | 
				
			||||||
@ -138,6 +138,13 @@ func (api *WebAPI) GetLog(r *Request) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		logs := api.Database.GetLogs(req.Since, req.Level)
 | 
							logs := api.Database.GetLogs(req.Since, req.Level)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if logs == nil {
 | 
				
			||||||
 | 
								r.Json(JsonResponse{
 | 
				
			||||||
 | 
									Ok: false,
 | 
				
			||||||
 | 
								}, 500)
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		logrus.WithFields(logrus.Fields{
 | 
							logrus.WithFields(logrus.Fields{
 | 
				
			||||||
			"getLogRequest": req,
 | 
								"getLogRequest": req,
 | 
				
			||||||
			"logCount":      len(*logs),
 | 
								"logCount":      len(*logs),
 | 
				
			||||||
 | 
				
			|||||||
@ -306,6 +306,13 @@ func (api *WebAPI) GetProjectList(r *Request) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	projects := api.Database.GetAllProjects(id)
 | 
						projects := api.Database.GetAllProjects(id)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if projects == nil {
 | 
				
			||||||
 | 
							r.Json(JsonResponse{
 | 
				
			||||||
 | 
								Ok: false,
 | 
				
			||||||
 | 
							}, 500)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	r.OkJson(JsonResponse{
 | 
						r.OkJson(JsonResponse{
 | 
				
			||||||
		Ok: true,
 | 
							Ok: true,
 | 
				
			||||||
		Content: GetProjectListResponse{
 | 
							Content: GetProjectListResponse{
 | 
				
			||||||
 | 
				
			|||||||
@ -4,6 +4,6 @@ import "github.com/sirupsen/logrus"
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func handleErr(err error) {
 | 
					func handleErr(err error) {
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		logrus.WithError(err).Fatal("Error during database operation!")
 | 
							logrus.WithError(err).Error("Error during database operation!")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -81,6 +81,9 @@ func (database *Database) GetLogs(since int64, level LogLevel) *[]LogEntry {
 | 
				
			|||||||
	rows, err := db.Query("SELECT * FROM log_entry WHERE timestamp > $1 AND level=$2",
 | 
						rows, err := db.Query("SELECT * FROM log_entry WHERE timestamp > $1 AND level=$2",
 | 
				
			||||||
		since, level)
 | 
							since, level)
 | 
				
			||||||
	handleErr(err)
 | 
						handleErr(err)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for rows.Next() {
 | 
						for rows.Next() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -36,11 +36,17 @@ func (database *Database) MakeProjectSnapshots() {
 | 
				
			|||||||
			   extract(epoch from now() at time zone 'utc')
 | 
								   extract(epoch from now() at time zone 'utc')
 | 
				
			||||||
		FROM project`)
 | 
							FROM project`)
 | 
				
			||||||
	handleErr(err)
 | 
						handleErr(err)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	inserted, _ := insertRes.RowsAffected()
 | 
						inserted, _ := insertRes.RowsAffected()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	res, err := db.Exec(`DELETE FROM project_monitoring_snapshot WHERE timestamp < $1`,
 | 
						res, err := db.Exec(`DELETE FROM project_monitoring_snapshot WHERE timestamp < $1`,
 | 
				
			||||||
		int64(time.Now().Unix())-int64(config.Cfg.MonitoringHistory.Seconds()))
 | 
							int64(time.Now().Unix())-int64(config.Cfg.MonitoringHistory.Seconds()))
 | 
				
			||||||
	handleErr(err)
 | 
						handleErr(err)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	deleted, _ := res.RowsAffected()
 | 
						deleted, _ := res.RowsAffected()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	logrus.WithFields(logrus.Fields{
 | 
						logrus.WithFields(logrus.Fields{
 | 
				
			||||||
@ -60,6 +66,9 @@ func (database *Database) GetMonitoringSnapshotsBetween(pid int64, from int, to
 | 
				
			|||||||
		worker_access_count, awaiting_verification_task_count, timestamp FROM project_monitoring_snapshot 
 | 
							worker_access_count, awaiting_verification_task_count, timestamp FROM project_monitoring_snapshot 
 | 
				
			||||||
		WHERE project=$1 AND timestamp BETWEEN $2 AND $3 ORDER BY TIMESTAMP DESC `, pid, from, to)
 | 
							WHERE project=$1 AND timestamp BETWEEN $2 AND $3 ORDER BY TIMESTAMP DESC `, pid, from, to)
 | 
				
			||||||
	handleErr(err)
 | 
						handleErr(err)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for rows.Next() {
 | 
						for rows.Next() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -91,6 +100,9 @@ func (database *Database) GetNMonitoringSnapshots(pid int64, count int) (ss *[]P
 | 
				
			|||||||
		worker_access_count, awaiting_verification_task_count, timestamp FROM project_monitoring_snapshot 
 | 
							worker_access_count, awaiting_verification_task_count, timestamp FROM project_monitoring_snapshot 
 | 
				
			||||||
		WHERE project=$1 ORDER BY TIMESTAMP DESC LIMIT $2`, pid, count)
 | 
							WHERE project=$1 ORDER BY TIMESTAMP DESC LIMIT $2`, pid, count)
 | 
				
			||||||
	handleErr(err)
 | 
						handleErr(err)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for rows.Next() {
 | 
						for rows.Next() {
 | 
				
			||||||
		s := ProjectMonitoringSnapshot{}
 | 
							s := ProjectMonitoringSnapshot{}
 | 
				
			||||||
 | 
				
			|||||||
@ -168,6 +168,9 @@ func (database Database) GetAllProjects(managerId int64) *[]Project {
 | 
				
			|||||||
		ORDER BY name`, managerId)
 | 
							ORDER BY name`, managerId)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	handleErr(err)
 | 
						handleErr(err)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for rows.Next() {
 | 
						for rows.Next() {
 | 
				
			||||||
		p := Project{}
 | 
							p := Project{}
 | 
				
			||||||
 | 
				
			|||||||
@ -156,6 +156,9 @@ func getSessionCtx(username string, password string, admin bool) *http.Client {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	if admin {
 | 
						if admin {
 | 
				
			||||||
		manager, _ := testApi.Database.ValidateCredentials([]byte(username), []byte(password))
 | 
							manager, _ := testApi.Database.ValidateCredentials([]byte(username), []byte(password))
 | 
				
			||||||
 | 
							if manager == nil {
 | 
				
			||||||
 | 
								return nil
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		manager.WebsiteAdmin = true
 | 
							manager.WebsiteAdmin = true
 | 
				
			||||||
		testApi.Database.UpdateManager(manager)
 | 
							testApi.Database.UpdateManager(manager)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
@ -59,7 +59,7 @@ func TestWebHookDontUpdateVersion(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	getResp := getProjectAsAdmin(resp.Id).Content
 | 
						getResp := getProjectAsAdmin(resp.Id).Content
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if getResp.Project.Version != "old" {
 | 
						if getResp.Project == nil || getResp.Project.Version != "old" {
 | 
				
			||||||
		t.Error()
 | 
							t.Error()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -93,7 +93,7 @@ func TestWebHookUpdateVersion(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	getResp := getProjectAsAdmin(resp.Id).Content
 | 
						getResp := getProjectAsAdmin(resp.Id).Content
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if getResp.Project.Version != "new" {
 | 
						if getResp.Project == nil || getResp.Project.Version != "new" {
 | 
				
			||||||
		t.Error()
 | 
							t.Error()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -139,8 +139,9 @@ func TestGetLogs(t *testing.T) {
 | 
				
			|||||||
		t.Error()
 | 
							t.Error()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if len(*r.Content.Logs) <= 0 {
 | 
						if r.Content.Logs == nil || len(*r.Content.Logs) <= 0 {
 | 
				
			||||||
		t.Error()
 | 
							t.Error()
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	debugFound := false
 | 
						debugFound := false
 | 
				
			||||||
 | 
				
			|||||||
@ -37,12 +37,13 @@ func TestCreateGetProject(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	getResp := getProjectAsAdmin(id).Content
 | 
						getResp := getProjectAsAdmin(id).Content
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if getResp.Project.Id != id {
 | 
						if getResp.Project == nil || getResp.Project.Id != id {
 | 
				
			||||||
		t.Error()
 | 
							t.Error()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if getResp.Project.Name != "Test name" {
 | 
						if getResp.Project == nil || getResp.Project.Name != "Test name" {
 | 
				
			||||||
		t.Error()
 | 
							t.Error()
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if getResp.Project.Version != "Test Version" {
 | 
						if getResp.Project.Version != "Test Version" {
 | 
				
			||||||
@ -147,8 +148,9 @@ func TestUpdateProjectValid(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	proj := getProjectAsAdmin(pid).Content
 | 
						proj := getProjectAsAdmin(pid).Content
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if proj.Project.Public != false {
 | 
						if proj.Project == nil || proj.Project.Public != false {
 | 
				
			||||||
		t.Error()
 | 
							t.Error()
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if proj.Project.Motd != "MotdB" {
 | 
						if proj.Project.Motd != "MotdB" {
 | 
				
			||||||
		t.Error()
 | 
							t.Error()
 | 
				
			||||||
@ -314,7 +316,8 @@ func TestHiddenProjectsNotShownInList(t *testing.T) {
 | 
				
			|||||||
	}, testUserCtx)
 | 
						}, testUserCtx)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if r.Ok != true {
 | 
						if r.Ok != true {
 | 
				
			||||||
		t.Error()
 | 
							t.Fail()
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	list := getProjectList(nil)
 | 
						list := getProjectList(nil)
 | 
				
			||||||
@ -417,6 +420,11 @@ func TestUserWithReadAccessShouldSeeHiddenProjectInList(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	list := getProjectList(testUserCtx)
 | 
						list := getProjectList(testUserCtx)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if list.Content.Projects == nil {
 | 
				
			||||||
 | 
							t.Fail()
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	found := false
 | 
						found := false
 | 
				
			||||||
	for _, p := range *list.Content.Projects {
 | 
						for _, p := range *list.Content.Projects {
 | 
				
			||||||
		if p.Id == pHidden.Content.Id {
 | 
							if p.Id == pHidden.Content.Id {
 | 
				
			||||||
@ -441,6 +449,11 @@ func TestAdminShouldSeeHiddenProjectInList(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	list := getProjectList(testAdminCtx)
 | 
						list := getProjectList(testAdminCtx)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if list.Content.Projects == nil {
 | 
				
			||||||
 | 
							t.Fail()
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	found := false
 | 
						found := false
 | 
				
			||||||
	for _, p := range *list.Content.Projects {
 | 
						for _, p := range *list.Content.Projects {
 | 
				
			||||||
		if p.Id == pHidden.Content.Id {
 | 
							if p.Id == pHidden.Content.Id {
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										4395
									
								
								web/angular/package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										4395
									
								
								web/angular/package-lock.json
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@ -32,7 +32,7 @@
 | 
				
			|||||||
        "zone.js": "~0.8.26"
 | 
					        "zone.js": "~0.8.26"
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "devDependencies": {
 | 
					    "devDependencies": {
 | 
				
			||||||
        "@angular-devkit/build-angular": "^0.803.21",
 | 
					        "@angular-devkit/build-angular": "^0.13.4",
 | 
				
			||||||
        "@angular/cli": "^7.2.4",
 | 
					        "@angular/cli": "^7.2.4",
 | 
				
			||||||
        "@angular/compiler-cli": "^7.2.6",
 | 
					        "@angular/compiler-cli": "^7.2.6",
 | 
				
			||||||
        "@angular/language-service": "~7.2.0",
 | 
					        "@angular/language-service": "~7.2.0",
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user