From 862df7ff73e271152ceaa72313ec08e6a10c44ba Mon Sep 17 00:00:00 2001 From: siwei xu Date: Mon, 16 Sep 2024 20:53:04 -0400 Subject: [PATCH] CMR-9848: Changing status returned in association and generic_association --- search-app/src/cmr/search/api/association.clj | 8 ++++---- search-app/src/cmr/search/api/generic_association.clj | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/search-app/src/cmr/search/api/association.clj b/search-app/src/cmr/search/api/association.clj index 721a730737..ef0d62e92a 100644 --- a/search-app/src/cmr/search/api/association.clj +++ b/search-app/src/cmr/search/api/association.clj @@ -24,10 +24,10 @@ :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 @@ -35,7 +35,7 @@ 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)) diff --git a/search-app/src/cmr/search/api/generic_association.clj b/search-app/src/cmr/search/api/generic_association.clj index 0731d3b011..6e40ee5074 100644 --- a/search-app/src/cmr/search/api/generic_association.clj +++ b/search-app/src/cmr/search/api/generic_association.clj @@ -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))