From f68012de0031ca9df9292e69bd940147840079fb Mon Sep 17 00:00:00 2001 From: Quentin Machu Date: Thu, 4 Feb 2016 22:11:49 -0500 Subject: [PATCH] api: fix 404->500 and NPE issues --- api/v1/models.go | 6 ++++-- api/v1/routes.go | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/api/v1/models.go b/api/v1/models.go index e87c7ca7..d0ae36a1 100644 --- a/api/v1/models.go +++ b/api/v1/models.go @@ -193,12 +193,14 @@ type Notification struct { func NotificationFromDatabaseModel(dbNotification database.VulnerabilityNotification, limit int, page, nextPage database.VulnerabilityNotificationPageNumber) Notification { var oldVuln *VulnerabilityWithLayers if dbNotification.OldVulnerability != nil { - *oldVuln = VulnerabilityWithLayersFromDatabaseModel(*dbNotification.OldVulnerability) + v := VulnerabilityWithLayersFromDatabaseModel(*dbNotification.OldVulnerability) + oldVuln = &v } var newVuln *VulnerabilityWithLayers if dbNotification.NewVulnerability != nil { - *newVuln = VulnerabilityWithLayersFromDatabaseModel(*dbNotification.NewVulnerability) + v := VulnerabilityWithLayersFromDatabaseModel(*dbNotification.NewVulnerability) + newVuln = &v } var nextPageStr string diff --git a/api/v1/routes.go b/api/v1/routes.go index 50fc1a3f..799b7e4b 100644 --- a/api/v1/routes.go +++ b/api/v1/routes.go @@ -326,7 +326,10 @@ func getNotification(w http.ResponseWriter, r *http.Request, p httprouter.Params } dbNotification, nextPage, err := ctx.Store.GetNotification(p.ByName("notificationName"), limit, page) - if err != nil { + if err == cerrors.ErrNotFound { + writeResponse(w, http.StatusNotFound, NotificationEnvelope{Error: &Error{err.Error()}}) + return deleteNotificationRoute, http.StatusNotFound + } else if err != nil { writeResponse(w, http.StatusInternalServerError, NotificationEnvelope{Error: &Error{err.Error()}}) return getNotificationRoute, http.StatusInternalServerError }