Skip to content

Commit

Permalink
Handle unexpected status from endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mdemare committed Nov 13, 2024
1 parent 97624cb commit eba180c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions src/nl/surf/eduhub_rio_mapper/ooapi/loader.clj
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,24 @@
(when-let [{:keys [username password]} gateway-credentials]
{:basic-auth [username password]}))
response-body (-> request http-utils/send-http-request :body (json/read-str :key-fn keyword))
endpoints (-> response-body :gateway :endpoints)]
(if (= http-status/not-found (get-in endpoints [(keyword institution-schac-home) :responseCode]))
(throw (ex-info "OOAPI object not found" {:status http-status/not-found
response-code (get-in response-body [:gateway :endpoints (keyword institution-schac-home) :responseCode])]
(condp = response-code
http-status/not-found
(throw (ex-info "OOAPI object not found" {:status response-code
:id id
:type type}))
(get-in response-body [:responses (keyword institution-schac-home)]))))
http-status/unauthorized
(throw (ex-info "Unauthorized for endpoint" {:status response-code
:id id
:type type}))

http-status/ok
(get-in response-body [:responses (keyword institution-schac-home)])

;; else
(throw (ex-info "Endpoint returns unexpected status" {:status response-code
:id id
:type type})))))

;; For type "offerings", loads all pages and merges them into "items"
(defn- ooapi-http-recursive-loader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
:headers {}},
:response
{:status 200,
:body "{\"gateway\":{\"requestId\":\"6LfiEpocGhUmtRCqcQOJz9\",\"request\":\"/education-specifications/9338214e-3978-484c-676d-427303a92748?returnTimelineOverrides=true\",\"endpoints\":{\"tester.rio-mapper.test.surfeduhub.nl\":{\"url\":\"https://tester.rio-mapper.test.surfeduhub.nl/api/ooapi/education-specifications/9338214e-3978-484c-676d-427303a92748?returnTimelineOverrides=true\",\"responseCode\":200,\"headers\":{\"content-type\":\"application/json; charset=utf-8\"}}}},\"responses\":{\"endpoint01.sandbox.jomco.nl\":{\"level\":\"bachelor\",\"organization\":\"22cb83ef-42ff-0583-2f25-2c576aba3ca4\",\"educationSpecificationType\":\"cluster\",\"educationSpecificationId\":\"9338214e-3978-484c-676d-427303a92748\",\"validFrom\":\"2004-03-31\",\"abbreviation\":\"AT\",\"validTo\":\"2038-09-13\",\"learningOutcomes\":[[{\"language\":\"en-GB\",\"value\":\"EN TRANSLATION: nieuw talent op het gebied van programmeren\"},{\"language\":\"nl-NL\",\"value\":\"NL VERTALING: nieuw talent op het gebied van programmeren\"}]],\"formalDocument\":\"no official document\",\"sector\":\"higher professional education\",\"name\":[{\"language\":\"en-GB\",\"value\":\"EN TRANSLATION: Automotive Technology\"},{\"language\":\"nl-NL\",\"value\":\"NL VERTALING: Automotive Technology\"}],\"primaryCode\":{\"codeType\":\"identifier\",\"code\":\"9338214e-3978-484c-676d-427303a92748\"},\"link\":\"https://universiteit-van-dreischor.nl/education-specifications/8338214e-3978-484c-676d-427303a92748\",\"fieldsOfStudy\":\"0213\",\"description\":[{\"language\":\"en-GB\",\"value\":\"EN TRANSLATION: Tutorials will be on agro-environment measures. In this final phase supporting lectures on these techniques. More recently attention is paid to EU trade policies in developing the most important current issues and conceptual approaches used in biorefinery of plants, cut flowers, fruits, etc.\"},{\"language\":\"nl-NL\",\"value\":\"NL VERTALING: Tutorials will be on agro-environment measures. In this final phase supporting lectures on these techniques. More recently attention is paid to EU trade policies in developing the most important current issues and conceptual approaches used in biorefinery of plants, cut flowers, fruits, etc.\"}],\"children\":[\"f151e068-3265-cf5a-84cc-bee97567dec1\"],\"levelOfQualification\":\"6\",\"consumers\":[{\"consumerKey\":\"rio\",\"category\":[\"business_and_project_support\"]}],\"studyLoad\":{\"value\":169,\"studyLoadUnit\":\"contacttime\"}}}}"}}
:body "{\"gateway\":{\"requestId\":\"6LfiEpocGhUmtRCqcQOJz9\",\"request\":\"/education-specifications/9338214e-3978-484c-676d-427303a92748?returnTimelineOverrides=true\",\"endpoints\":{\"endpoint01.sandbox.jomco.nl\":{\"url\":\"https://endpoint01.sandbox.jomco.nl/api/ooapi/education-specifications/9338214e-3978-484c-676d-427303a92748?returnTimelineOverrides=true\",\"responseCode\":200,\"headers\":{\"content-type\":\"application/json; charset=utf-8\"}}}},\"responses\":{\"endpoint01.sandbox.jomco.nl\":{\"level\":\"bachelor\",\"organization\":\"22cb83ef-42ff-0583-2f25-2c576aba3ca4\",\"educationSpecificationType\":\"cluster\",\"educationSpecificationId\":\"9338214e-3978-484c-676d-427303a92748\",\"validFrom\":\"2004-03-31\",\"abbreviation\":\"AT\",\"validTo\":\"2038-09-13\",\"learningOutcomes\":[[{\"language\":\"en-GB\",\"value\":\"EN TRANSLATION: nieuw talent op het gebied van programmeren\"},{\"language\":\"nl-NL\",\"value\":\"NL VERTALING: nieuw talent op het gebied van programmeren\"}]],\"formalDocument\":\"no official document\",\"sector\":\"higher professional education\",\"name\":[{\"language\":\"en-GB\",\"value\":\"EN TRANSLATION: Automotive Technology\"},{\"language\":\"nl-NL\",\"value\":\"NL VERTALING: Automotive Technology\"}],\"primaryCode\":{\"codeType\":\"identifier\",\"code\":\"9338214e-3978-484c-676d-427303a92748\"},\"link\":\"https://universiteit-van-dreischor.nl/education-specifications/8338214e-3978-484c-676d-427303a92748\",\"fieldsOfStudy\":\"0213\",\"description\":[{\"language\":\"en-GB\",\"value\":\"EN TRANSLATION: Tutorials will be on agro-environment measures. In this final phase supporting lectures on these techniques. More recently attention is paid to EU trade policies in developing the most important current issues and conceptual approaches used in biorefinery of plants, cut flowers, fruits, etc.\"},{\"language\":\"nl-NL\",\"value\":\"NL VERTALING: Tutorials will be on agro-environment measures. In this final phase supporting lectures on these techniques. More recently attention is paid to EU trade policies in developing the most important current issues and conceptual approaches used in biorefinery of plants, cut flowers, fruits, etc.\"}],\"children\":[\"f151e068-3265-cf5a-84cc-bee97567dec1\"],\"levelOfQualification\":\"6\",\"consumers\":[{\"consumerKey\":\"rio\",\"category\":[\"business_and_project_support\"]}],\"studyLoad\":{\"value\":169,\"studyLoadUnit\":\"contacttime\"}}}}"}}

0 comments on commit eba180c

Please sign in to comment.