philbooth · GitHub

@philbooth

In  75815f2 , we added an error for email-sending failure to some routes,
originally a 500. Then in  17e787b , we switched it to be a 422 because
the 500 was noisily alerting us in Sentry for lots of cases where a user
had just misspelled their email address. Then jrgm pointed out that we
already have error types in place for bounce/complaint checking and we
should really be propagating those rather than inventing a new error
type where possible.
So this commit wraps up the `cannotSendEmail` logic into a little helper
function that:
1. Checks the origin error and propagates that if it is a bounce or
   complaint.
2. Otherwise, returns a 422 if the email address was not previously
   verified.
3. Otherwise, returns a 500.

Read the original on github.com ↗