Skip to content

Commit

Permalink
api: fix 404->500 and NPE issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin-M authored and jzelinskie committed Feb 24, 2016
1 parent 7c11e4e commit f68012d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 4 additions & 2 deletions api/v1/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion api/v1/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit f68012d

Please sign in to comment.