Fork me on GitHub
#clojurescript
<
2024-07-26
>
Priyankaa16:07:50

Hi, i have updated Axios to 1.6.4 getting an issue - typeerror: module$node_modules$axios$index is not a function in clojurescript in axios:1.6.4 for the below code - (defn request-api ([endpoint method] (request-api endpoint method nil)) ([endpoint method data] (p/let [token (get-token)] (axios (-> {:url (str "/api" endpoint) :method (-> method name str/capitalize) :headers {:Authorization (str "JWT " token)}} (cond-> (some? data) (assoc :data data)) (->js))))))

p-himik16:07:09

I'd say the import is wrong.

Priyankaa16:07:39

(ns numbered-headings.ui.remote (:require ["axios" :as axios] ["cheerio" :as cheerio] [cljs-bean.core :refer [->clj ->js]] [clojure.string :as str] [com.fulcrologic.fulcro.algorithms.tx-processing :as txn] [com.wsscode.pathom3.connect.indexes :as pci] [com.wsscode.pathom3.connect.operation :as pco] [com.wsscode.pathom3.connect.runner :as pcr] [com.wsscode.pathom3.interface.async.eql :as p.a.eql] [com.wsscode.pathom3.plugin :as p.plugin] [edn-query-language.core :as eql] [numbered-headings.constants :as constants] [numbered-headings.numbering-config :as numbering-config] [numbered-headings.numbering.atlas-doc-format :as atlas-doc-format] [numbered-headings.numbering.main :as numbering] [numbered-headings.server.utils :as utils] [numbered-headings.space-config :as space-config] [numbered-headings.global-config :as global-config] [numbered-headings.ui.amplitude-client :as amplitude-client] [numbered-headings.ui.helper :as helper] [promesa.core :as p]))

Priyankaa16:07:50

Any issue in any above import for 1.6.4?

p-himik16:07:07

See what (js/console.log axios) outputs.

p-himik16:07:19

Instead of calling (axios ...), try (axios/Axios ...).

p-himik16:07:40

Alternatively, try importing ["axios$default" :as axios].

🙌 1
Priyankaa16:07:25

let me try and update thx

Priyankaa16:07:36

Worked .. thanks a lot 🙂

👍 1
Priyankaa19:07:07

Requesting failing (403) for below code base too after axios 1.6.4 and Aws4-axios 3.3.6 - any idea why- (ns numbered-headings.server.analytics-helper
  (:require
    [numbered-headings.server.log :as log]
    [numbered-headings.constants :as constants]
    ["axios" :as axios]
    ["aws4-axios" :refer [aws4Interceptor]]))

(defn register-with-ac [clientkey event]
  (let [instance (->
                   (axios/create
                     (clj->js
                       {:baseURL js/process.env.OPEN_API_AC_ENDPOINT
                        :headers {:appkey constants/nh-app-key}})))
        interseptor (aws4Interceptor
                      (clj->js
                        {:region js/process.env.AWS_REGION
                         :service "execute-api"})
                      (clj->js
                        {:accessKeyId js/process.env.AWS_ACCESS_KEY_ID
                         :secretAccessKey js/process.env.AWS_SECRET_ACCESS_KEY}))]
    (.use (.. instance -interceptors -request) interseptor)
    (log/info
      {:message "Registering into AC for the tenant"
       :clientkey clientkey})
    (->
      ((.-post instance) constants/register-path (clj->js event))
      (.then (fn [response] (.log js/console response)))
      (.catch (fn [error] (.log js/console error))))))

Priyankaa19:07:17

AxiosError: Request failed with status code 403

p-himik20:07:21

Check why your server returns HTTP 403, which conditions are not satisfied, and why the client sends data that doesn't satisfy those conditions. Apart from that very generic advice, I can't really say anything about that error.

🙏 1