api: fix 404->500 and NPE issues

This commit is contained in:
Quentin Machu 2016-02-04 22:11:49 -05:00 committed by Jimmy Zelinskie
parent 7c11e4eb5d
commit f68012de00
2 changed files with 8 additions and 3 deletions

View File

@ -193,12 +193,14 @@ type Notification struct {
func NotificationFromDatabaseModel(dbNotification database.VulnerabilityNotification, limit int, page, nextPage database.VulnerabilityNotificationPageNumber) Notification { func NotificationFromDatabaseModel(dbNotification database.VulnerabilityNotification, limit int, page, nextPage database.VulnerabilityNotificationPageNumber) Notification {
var oldVuln *VulnerabilityWithLayers var oldVuln *VulnerabilityWithLayers
if dbNotification.OldVulnerability != nil { if dbNotification.OldVulnerability != nil {
*oldVuln = VulnerabilityWithLayersFromDatabaseModel(*dbNotification.OldVulnerability) v := VulnerabilityWithLayersFromDatabaseModel(*dbNotification.OldVulnerability)
oldVuln = &v
} }
var newVuln *VulnerabilityWithLayers var newVuln *VulnerabilityWithLayers
if dbNotification.NewVulnerability != nil { if dbNotification.NewVulnerability != nil {
*newVuln = VulnerabilityWithLayersFromDatabaseModel(*dbNotification.NewVulnerability) v := VulnerabilityWithLayersFromDatabaseModel(*dbNotification.NewVulnerability)
newVuln = &v
} }
var nextPageStr string var nextPageStr string

View File

@ -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) 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()}}) writeResponse(w, http.StatusInternalServerError, NotificationEnvelope{Error: &Error{err.Error()}})
return getNotificationRoute, http.StatusInternalServerError return getNotificationRoute, http.StatusInternalServerError
} }