-
- Downloads
Fix constantly checking token on error (#23815)
* Fix constantly checking token on error We were catching `clojure.lang.ExceptionInfo` which only catches a small subset of errors and not any related to what might be thrown in network calls. The reason this affected us is that the cache will cache this value but keep trying what is throwing the error. So each time we look at token features it attempts again and throws an error. If we instead do what the code _meant_ to do and we return a value indicating there was an error, we are all good. Example: ```clojure premium-features=> (defn is-odd? [x] (println "computing for " x) (if (odd? x) true (throw (ex-info "boom" {})))) premium-features=> (def modd (memoize/ttl is-odd? :ttl/threshold 30000)) premium-features=> (modd 3) computing for 3 true premium-features=> (modd 5) computing for 5 true premium-features=> (modd 3) true premium-features=> (modd 2) computing for 2 Execution error (ExceptionInfo) at metabase.public-settings.premium-features/is-odd? (REPL:289). boom premium-features=> (modd 2) computing for 2 Execution error (ExceptionInfo) at metabase.public-settings.premium-features/is-odd? (REPL:289). boom ``` Note that `(modd 2)` keeps attempting to compute for 2 since it throws an error rather than returning a value indicating an error. When the token check throws an error: ```clojure premium-features=> (fetch-token-status (apply str (repeat 64 "b"))) Execution error (UnknownHostException) at java.net.Inet6AddressImpl/lookupAllHostAddr (Inet6AddressImpl.java:-2). store.metabase.com: nodename nor servname provided, or not known ``` When the token check returns a value indicating an error: ```clojure premium-features=> (fetch-token-status (apply str (repeat 64 "b"))) {:valid false, :status "Unable to validate token", :error-details "store.metabase.com: nodename nor servname provided, or not known"} ``` (both instances were with wifi turned off locally) * add test * Assert we only call the api once when it throws an error before this PR we would make a call for each setting (perhaps more). Each time trying to hit the endpoint. Now it catches those errors and reports not a valid token
Please register or sign in to comment