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

NullPointerException on SFDC API errors. #25

Open
kubrack opened this issue Jun 29, 2023 · 1 comment
Open

NullPointerException on SFDC API errors. #25

kubrack opened this issue Jun 29, 2023 · 1 comment

Comments

@kubrack
Copy link
Contributor

kubrack commented Jun 29, 2023

Currently salesforce.core/request doesn't handle properly the case when SFDC API returns error.
There is try/catch around clj-http.client/request but then parse-limit-info crashes with NullPointerException due to absence [:headers "sforce-limit-info"] in the resp.

Even when pass through the parse-limit-info, the salesforce.core/request returns nil instead of SFDC error message since exception's :body is already extracted.

Please consider the diff:

--- a/src/salesforce/core.clj
+++ b/src/salesforce/core.clj
@@ -1,6 +1,5 @@
 (ns salesforce.core
   (:require
-   [clojure.string :as str]
    [cheshire.core :as json]
    [clj-http.client :as http]
    [clojure.string :as str]
@@ -71,10 +70,10 @@
                           {:method method
                            :url full-url
                            :headers {"Authorization" (str "Bearer " (:access_token token))}}))
-                  (catch Exception e (:body (ex-data e))))]
-    (-> (get-in resp [:headers "sforce-limit-info"]) ;; Record limit info in atom
-        (parse-limit-info)
-        ((partial reset! limit-info)))
+                  (catch Exception e (ex-data e)))]
+    (some-> (get-in resp [:headers "sforce-limit-info"]) ;; Record limit info in atom
+            (parse-limit-info)
+            ((partial reset! limit-info)))
     (-> resp
         :body
         (json/decode true))))

BEFORE

=> (sf/so->objects auth)
Execution error (NullPointerException) at (REPL:1).
null

AFTER

=> (sf/so->objects auth)
({:message "The REST API is not enabled for this Organization.", :errorCode "API_DISABLED_FOR_ORG"})
kubrack added a commit to kubrack/salesforce that referenced this issue Jun 29, 2023
kubrack added a commit to kubrack/salesforce that referenced this issue Jun 29, 2023
owainlewis added a commit that referenced this issue Dec 6, 2023
…errors_#25

NullPointerException on SFDC API errors #25
@dthayer-oppfi
Copy link

Can we get a release that includes the fix from #26 ? Then we can close out this issue properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants