v1: return object on PUT/POST
This change also improves error handling around InsertVulnerability.
This commit is contained in:
parent
c06df1affd
commit
771e35def0
@ -211,11 +211,17 @@ func postVulnerability(w http.ResponseWriter, r *http.Request, p httprouter.Para
|
|||||||
|
|
||||||
err = ctx.Store.InsertVulnerabilities([]database.Vulnerability{vuln}, true)
|
err = ctx.Store.InsertVulnerabilities([]database.Vulnerability{vuln}, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeResponse(w, r, http.StatusInternalServerError, VulnerabilityEnvelope{Error: &Error{err.Error()}})
|
switch err.(type) {
|
||||||
return postVulnerabilityRoute, http.StatusInternalServerError
|
case *cerrors.ErrBadRequest:
|
||||||
|
writeResponse(w, r, http.StatusBadRequest, VulnerabilityEnvelope{Error: &Error{err.Error()}})
|
||||||
|
return postVulnerabilityRoute, http.StatusBadRequest
|
||||||
|
default:
|
||||||
|
writeResponse(w, r, http.StatusInternalServerError, VulnerabilityEnvelope{Error: &Error{err.Error()}})
|
||||||
|
return postVulnerabilityRoute, http.StatusInternalServerError
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
w.WriteHeader(http.StatusCreated)
|
writeResponse(w, r, http.StatusCreated, VulnerabilityEnvelope{Vulnerability: request.Vulnerability})
|
||||||
return postVulnerabilityRoute, http.StatusCreated
|
return postVulnerabilityRoute, http.StatusCreated
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,11 +272,17 @@ func putVulnerability(w http.ResponseWriter, r *http.Request, p httprouter.Param
|
|||||||
|
|
||||||
err = ctx.Store.InsertVulnerabilities([]database.Vulnerability{vuln}, true)
|
err = ctx.Store.InsertVulnerabilities([]database.Vulnerability{vuln}, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeResponse(w, r, http.StatusInternalServerError, VulnerabilityEnvelope{Error: &Error{err.Error()}})
|
switch err.(type) {
|
||||||
return putVulnerabilityRoute, http.StatusInternalServerError
|
case *cerrors.ErrBadRequest:
|
||||||
|
writeResponse(w, r, http.StatusBadRequest, VulnerabilityEnvelope{Error: &Error{err.Error()}})
|
||||||
|
return putVulnerabilityRoute, http.StatusBadRequest
|
||||||
|
default:
|
||||||
|
writeResponse(w, r, http.StatusInternalServerError, VulnerabilityEnvelope{Error: &Error{err.Error()}})
|
||||||
|
return putVulnerabilityRoute, http.StatusInternalServerError
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
w.WriteHeader(http.StatusOK)
|
writeResponse(w, r, http.StatusOK, VulnerabilityEnvelope{Vulnerability: request.Vulnerability})
|
||||||
return putVulnerabilityRoute, http.StatusOK
|
return putVulnerabilityRoute, http.StatusOK
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -328,15 +340,22 @@ func putFix(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx *co
|
|||||||
}
|
}
|
||||||
|
|
||||||
err = ctx.Store.InsertVulnerabilityFixes(p.ByName("vulnerabilityNamespace"), p.ByName("vulnerabilityName"), []database.FeatureVersion{dbFix})
|
err = ctx.Store.InsertVulnerabilityFixes(p.ByName("vulnerabilityNamespace"), p.ByName("vulnerabilityName"), []database.FeatureVersion{dbFix})
|
||||||
if err == cerrors.ErrNotFound {
|
if err != nil {
|
||||||
writeResponse(w, r, http.StatusNotFound, FeatureEnvelope{Error: &Error{err.Error()}})
|
switch err.(type) {
|
||||||
return putFixRoute, http.StatusNotFound
|
case *cerrors.ErrBadRequest:
|
||||||
} else if err != nil {
|
writeResponse(w, r, http.StatusBadRequest, FeatureEnvelope{Error: &Error{err.Error()}})
|
||||||
writeResponse(w, r, http.StatusInternalServerError, FeatureEnvelope{Error: &Error{err.Error()}})
|
return putFixRoute, http.StatusBadRequest
|
||||||
return putFixRoute, http.StatusInternalServerError
|
default:
|
||||||
|
if err == cerrors.ErrNotFound {
|
||||||
|
writeResponse(w, r, http.StatusNotFound, FeatureEnvelope{Error: &Error{err.Error()}})
|
||||||
|
return putFixRoute, http.StatusNotFound
|
||||||
|
}
|
||||||
|
writeResponse(w, r, http.StatusInternalServerError, FeatureEnvelope{Error: &Error{err.Error()}})
|
||||||
|
return putFixRoute, http.StatusInternalServerError
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
w.WriteHeader(http.StatusOK)
|
writeResponse(w, r, http.StatusOK, FeatureEnvelope{Feature: request.Feature})
|
||||||
return putFixRoute, http.StatusOK
|
return putFixRoute, http.StatusOK
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user