Skip to content

Commit

Permalink
CMR-9848: Changing status returned in association and generic_associa…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
siwei xu authored and siwei xu committed Sep 17, 2024
1 parent 069ad9a commit 862df7f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions search-app/src/cmr/search/api/association.clj
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@
:body (json/generate-string (util/snake-case-data data))
:headers {"Content-Type" mt/json}}))

(defn- results-contain-errors?
"Returns true if the results contain :errors"
(defn- all-results-contain-errors?
"Returns true if the all results contain :errors"
[results]
(seq (filter #(some? (:errors %)) results)))
(not (some #(nil? (:errors %)) results)))

(defn association-results->status-code
"Check for concept-types requiring error status to be returned. This is currently :service and :variable
If the concept-type is error-sensitive the function will check for any errors in the results, and will return 400 if
any are errors are present. Otherwise it will return 200"
[concept-type results]
(if (some #{concept-type} '(:variable :service :tool))
(if (results-contain-errors? results)
(if (all-results-contain-errors? results)
400
200)
200))
Expand Down
8 changes: 4 additions & 4 deletions search-app/src/cmr/search/api/generic_association.clj
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
:body (json/generate-string (util/snake-case-data data))
:headers {"Content-Type" mt/json}}))

(defn- results-contain-errors?
"Returns true if the results contain :errors"
(defn- all-results-contain-errors?
"Returns true if every single result contains :errors"
[results]
(seq (filter #(some? (:errors %)) results)))
(not (some #(nil? (:errors %)) results)))

(defn- results->status-code
"Return status code depending on if results contains error."
[results]
(if (results-contain-errors? results)
(if (all-results-contain-errors? results)
400
200))

Expand Down

0 comments on commit 862df7f

Please sign in to comment.