Skip to content
Snippets Groups Projects
Unverified Commit 52336b97 authored by dpsutton's avatar dpsutton Committed by GitHub
Browse files

Check email test errors for javax.mail.AuthenticationFailedException (#23921)

* Check email test errors for javax.mail.AuthenticationFailedException

Authing with Office365 led to a less-than-great user experience. If you
type in the wrong username or password, we would display an unhelpful
message:

> Sorry, something went wrong. Please try again. Error::Exception
reading response.Read timed out.

This is an error from an inner nested exception which looks like:
```clojure
(javax.mail.AuthenticationFailedException.
 "" ;; Office365 returns auth exception with no message so we only saw "Read timed out" prior
 (javax.mail.MessagingException.
  "Exception reading response"
  (java.net.SocketTimeoutException. "Read timed out")))
```

We didn't get any message from the AuthenticationFailedException so our
humanization strategy only went on the underlying "Read timed out". Now
we can check against the error class and use that information.

* Little bit of clarity

better function name (`check` -> `match-error`), better arg name (
`regex|exception-class` -> `regex-or-exception-class`), full argument
names `m` -> `message` and `es` -> `exceptions`
parent 5e49508d
Branches
Tags
No related merge requests found
......@@ -31,9 +31,16 @@
:email-smtp-port "Wrong host or port"}}
creds-error {:errors {:email-smtp-username "Wrong username or password"
:email-smtp-password "Wrong username or password"}}
message (str/join ": " (map ex-message (u/full-exception-chain error)))]
(log/warn "Problem connecting to mail server:" message)
(condp re-find message
exceptions (u/full-exception-chain error)
message (str/join ": " (map ex-message exceptions))
match-error (fn match-error [regex-or-exception-class [message exceptions]]
(cond (instance? java.util.regex.Pattern regex-or-exception-class)
(re-find regex-or-exception-class message)
(class? regex-or-exception-class)
(some (partial instance? regex-or-exception-class) exceptions)))]
(log/warn "Problem connecting to mail server:" message)
(condp match-error [message exceptions]
;; bad host = "Unknown SMTP host: foobar"
#"^Unknown SMTP host:.*$"
conn-error
......@@ -54,8 +61,10 @@
#"^435 4.7.8 Error: authentication failed:.*$"
creds-error
javax.mail.AuthenticationFailedException
creds-error
;; everything else :(
#".*"
{:message (str "Sorry, something went wrong. Please try again. Error: " message)}))))
(defn- humanize-email-corrections
......
......@@ -14,7 +14,16 @@
{::email/error (Exception. "Couldn't connect to host, port: foobar, 789; timeout 1000: foobar")})))
(is (= {:message "Sorry, something went wrong. Please try again. Error: Some unexpected message"}
(#'api.email/humanize-error-messages
{::email/error (Exception. "Some unexpected message")}))))
{::email/error (Exception. "Some unexpected message")})))
(testing "Checks error classes for auth errors (#23918)"
(let [exception (javax.mail.AuthenticationFailedException.
"" ;; Office365 returns auth exception with no message so we only saw "Read timed out" prior
(javax.mail.MessagingException.
"Exception reading response"
(java.net.SocketTimeoutException. "Read timed out")))]
(is (= {:errors {:email-smtp-username "Wrong username or password"
:email-smtp-password "Wrong username or password"}}
(#'api.email/humanize-error-messages {::email/error exception}))))))
(defn- email-settings
[]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment