fix(server,api): return 'not found' errors

This commit is contained in:
wpetit 2023-04-20 12:22:30 +02:00
parent 3d01cf0f93
commit 51e1dc3b2d
1 changed files with 12 additions and 0 deletions

View File

@ -58,6 +58,12 @@ func (s *Server) updateSpec(w http.ResponseWriter, r *http.Request) {
updateSpecReq.SpecData(), updateSpecReq.SpecData(),
) )
if err != nil { if err != nil {
if errors.Is(err, datastore.ErrNotFound) {
api.ErrorResponse(w, http.StatusNotFound, ErrCodeNotFound, nil)
return
}
if errors.Is(err, datastore.ErrUnexpectedRevision) { if errors.Is(err, datastore.ErrUnexpectedRevision) {
api.ErrorResponse(w, http.StatusConflict, ErrCodeUnexpectedRevision, nil) api.ErrorResponse(w, http.StatusConflict, ErrCodeUnexpectedRevision, nil)
@ -87,6 +93,12 @@ func (s *Server) getAgentSpecs(w http.ResponseWriter, r *http.Request) {
specs, err := s.agentRepo.GetSpecs(ctx, agentID) specs, err := s.agentRepo.GetSpecs(ctx, agentID)
if err != nil { if err != nil {
if errors.Is(err, datastore.ErrNotFound) {
api.ErrorResponse(w, http.StatusNotFound, ErrCodeNotFound, nil)
return
}
logger.Error(ctx, "could not list specs", logger.E(errors.WithStack(err))) logger.Error(ctx, "could not list specs", logger.E(errors.WithStack(err)))
api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil) api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil)