Skip to content

Commit 62853bc

Browse files
BCDA-9385: Update bulk request response when attribution file not found (#1201)
## 🎫 Ticket https://jira.cms.gov/browse/BCDA-9385 ## 🛠 Changes - updated response when attribution file is not found from HTTP 500 -> 404. - updated tests ## ℹ️ Context HTTP 500s should be reserved for serious, unexpected errors. This was a result of requesting expired runout data, which caused alerting to trigger; this is an expected outcome around this time of the PY and should be handled more gracefully. An additional ticket has been created to give a more informative/helpful response to our entities when runout data has been requested past its expiry date: https://jira.cms.gov/browse/BCDA-9386 <!-- If any of the following security implications apply, this PR must not be merged without Stephen Walter's approval. Explain in this section and add @SJWalter11 as a reviewer. - Adds a new software dependency or dependencies. - Modifies or invalidates one or more of our security controls. - Stores or transmits data that was not stored or transmitted before. - Requires additional review of security implications for other reasons. --> ## 🧪 Validation Tests updated and passing.
1 parent 157a315 commit 62853bc

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

bcda/api/requests.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,14 @@ func (h *Handler) bulkRequest(w http.ResponseWriter, r *http.Request, reqType co
526526
fileType,
527527
)
528528
if err != nil {
529-
logger.Error("error finding latest cclf file: %+v", err)
530-
h.RespWriter.Exception(r.Context(), w, http.StatusInternalServerError, responseutils.DbErr, "")
529+
// TODO: this can occur when runout data is expired, we should update error handling: BCDA-9386
530+
if errors.As(err, &service.CCLFNotFoundError{}) {
531+
logger.Warningf("cclf file not found: %+v", err)
532+
h.RespWriter.Exception(r.Context(), w, http.StatusNotFound, responseutils.NotFoundErr, "failed to start job; attribution file not found.")
533+
return
534+
}
535+
logger.Errorf("failed to retrieve latest cclf file: %+v", err)
536+
h.RespWriter.Exception(r.Context(), w, http.StatusInternalServerError, responseutils.DbErr, responseutils.DbErr)
531537
return
532538
}
533539

bcda/api/requests_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ func (s *RequestsTestSuite) TestRunoutEnabled() {
130130
}{
131131
{"Successful", nil, http.StatusAccepted, apiVersionOne, true},
132132
{"Successful v2", nil, http.StatusAccepted, apiVersionTwo, true},
133-
{"FindCCLFFiles error", CCLFNotFoundOperationOutcomeError{}, http.StatusInternalServerError, apiVersionOne, false},
134-
{"FindCCLFFiles error v2", CCLFNotFoundOperationOutcomeError{}, http.StatusInternalServerError, apiVersionTwo, false},
133+
{"FindCCLFFiles error", CCLFNotFoundOperationOutcomeError{}, http.StatusNotFound, apiVersionOne, false},
134+
{"FindCCLFFiles error v2", DatabaseError{}, http.StatusInternalServerError, apiVersionTwo, false},
135135
{constants.DefaultError, QueueError{}, http.StatusInternalServerError, apiVersionOne, true},
136136
{constants.DefaultError + " v2", QueueError{}, http.StatusInternalServerError, apiVersionTwo, true},
137137
}
@@ -155,7 +155,9 @@ func (s *RequestsTestSuite) TestRunoutEnabled() {
155155
mockSvc.On("GetLatestCCLFFile", testUtils.CtxMatcher, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(&models.CCLFFile{PerformanceYear: 24}, nil)
156156
enqueuer.On("AddPrepareJob", mock.Anything, mock.Anything).Return(nil)
157157
case CCLFNotFoundOperationOutcomeError{}:
158-
mockSvc.On("GetLatestCCLFFile", testUtils.CtxMatcher, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, errors.New("db error"))
158+
mockSvc.On("GetLatestCCLFFile", testUtils.CtxMatcher, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, service.CCLFNotFoundError{})
159+
case DatabaseError{}:
160+
mockSvc.On("GetLatestCCLFFile", testUtils.CtxMatcher, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, errors.New("database error"))
159161
case QueueError{}:
160162
mockSvc.On("GetLatestCCLFFile", testUtils.CtxMatcher, mock.AnythingOfType("string"), mock.AnythingOfType("time.Time"), mock.AnythingOfType("time.Time"), mock.Anything).
161163
Return(&models.CCLFFile{PerformanceYear: 24}, nil)
@@ -1229,3 +1231,9 @@ type QueueError struct{}
12291231
func (e QueueError) Error() string {
12301232
return "error"
12311233
}
1234+
1235+
type DatabaseError struct{}
1236+
1237+
func (e DatabaseError) Error() string {
1238+
return "error"
1239+
}

0 commit comments

Comments
 (0)