Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BCDA-7446 - update content-type header for OperationOutcome responses to fhir+json #873

Merged
merged 3 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion bcda/api/requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -783,8 +783,12 @@ func (s *RequestsTestSuite) TestJobStatusErrorHandling() {
h.JobStatus(w, req)
s.Equal(tt.responseHeader, w.Code)
switch tt.responseHeader {
case http.StatusOK, http.StatusBadRequest, http.StatusNotFound, http.StatusGone:
case http.StatusBadRequest, http.StatusNotFound, http.StatusGone:
s.Equal(constants.FHIRJsonContentType, w.Header().Get("Content-Type"))
case http.StatusOK:
s.Equal(constants.JsonContentType, w.Header().Get("Content-Type"))
case http.StatusAccepted:
s.Equal("", w.Header().Get("Content-Type"))
}

})
Expand Down
5 changes: 3 additions & 2 deletions bcda/responseutils/v2/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@ func CreateOpOutcome(severity fhircodes.IssueSeverityCode_Value, code fhircodes.
}

func WriteError(outcome *fhirmodelOO.OperationOutcome, w http.ResponseWriter, code int) {

w.Header().Set(constants.ContentType, constants.JsonContentType)
//Write application/fhir+json header on OperationOutcome responses
//https://build.fhir.org/ig/HL7/bulk-data/export.html#response---error-status-1
w.Header().Set(constants.ContentType, constants.FHIRJsonContentType)
w.WriteHeader(code)
_, err := WriteOperationOutcome(w, outcome)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions bcda/responseutils/v2/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ func (s *ResponseUtilsWriterTestSuite) TestResponseWriterException() {
assert.Equal(s.T(), "TestResponseWriterExcepton", respOO.Issue[0].Details.Coding[0].Display.Value)
assert.Equal(s.T(), "TestResponseWriterExcepton", respOO.Issue[0].Details.Text.Value)
assert.Equal(s.T(), responseutils.RequestErr, respOO.Issue[0].Details.Coding[0].Code.Value)
assert.Equal(s.T(), constants.FHIRJsonContentType, s.rr.Header().Get("Content-Type"))

}

func (s *ResponseUtilsWriterTestSuite) TestResponseWriterNotFound() {
Expand All @@ -70,6 +72,8 @@ func (s *ResponseUtilsWriterTestSuite) TestResponseWriterNotFound() {
assert.Equal(s.T(), "TestResponseWriterNotFound", respOO.Issue[0].Details.Coding[0].Display.Value)
assert.Equal(s.T(), "TestResponseWriterNotFound", respOO.Issue[0].Details.Text.Value)
assert.Equal(s.T(), responseutils.RequestErr, respOO.Issue[0].Details.Coding[0].Code.Value)
assert.Equal(s.T(), constants.FHIRJsonContentType, s.rr.Header().Get("Content-Type"))

}

func (s *ResponseUtilsWriterTestSuite) TestCreateOpOutcome() {
Expand Down
2 changes: 1 addition & 1 deletion bcda/responseutils/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func CreateOpOutcome(severity fhircodes.IssueSeverityCode_Value, code fhircodes.
}

func WriteError(outcome *fhirmodels.OperationOutcome, w http.ResponseWriter, code int) {
w.Header().Set(constants.ContentType, constants.JsonContentType)
w.Header().Set(constants.ContentType, constants.FHIRJsonContentType)
if code == http.StatusServiceUnavailable {
includeRetryAfterHeader(w)
}
Expand Down
3 changes: 3 additions & 0 deletions bcda/responseutils/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ func (s *ResponseUtilsWriterTestSuite) TestResponseWriterException() {
assert.Equal(s.T(), "TestResponseWriterExcepton", respOO.Issue[0].Details.Coding[0].Display.Value)
assert.Equal(s.T(), "TestResponseWriterExcepton", respOO.Issue[0].Details.Text.Value)
assert.Equal(s.T(), RequestErr, respOO.Issue[0].Details.Coding[0].Code.Value)
assert.Equal(s.T(), constants.FHIRJsonContentType, s.rr.Header().Get("Content-Type"))

}

func (s *ResponseUtilsWriterTestSuite) TestResponseWriterNotFound() {
Expand All @@ -69,6 +71,7 @@ func (s *ResponseUtilsWriterTestSuite) TestResponseWriterNotFound() {
assert.Equal(s.T(), "TestResponseWriterNotFound", respOO.Issue[0].Details.Coding[0].Display.Value)
assert.Equal(s.T(), "TestResponseWriterNotFound", respOO.Issue[0].Details.Text.Value)
assert.Equal(s.T(), RequestErr, respOO.Issue[0].Details.Coding[0].Code.Value)
assert.Equal(s.T(), constants.FHIRJsonContentType, s.rr.Header().Get("Content-Type"))
}

func (s *ResponseUtilsWriterTestSuite) TestCreateOpOutcome() {
Expand Down
Loading