-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update SendGrid Adapter to return ok/error tuple (#572)
What changed? ============== We update the `SendGridAdapter` to abide by the new Adapter behaviour. The adapter now returns an `{:ok, email}` or `{:error, error}`. As part of this work, we create the `build_api_error` function to replace the `raise_api_error` function. Note on implementation with throw/catch --------------------------------------- Building SendGrid's body requires a lot of deeply nested data manipulation. Nested deep within some of the branching logic was some code that raised errors. Rather than returning an error tuple at a really low level and have to bubble up the error all the way til it's returned, we opted for a simpler approach: throwing and catching the errors. We throw and catch `{:error, error}` when we used to `raise error`. It's possible we could do something different in the future, like bubbling up the errors and returning them without having to resort to `throw` and `catch`, but right now we want to minimize the number of changes for these `raise`s deep in the call stack. Raising (not returning) configuration errors -------------------------------- While working on this, an important question came up. Should we raise or return an error because of a missing API key? Currently we raise. I think it's okay to raise an error in that case because it's a configuration issue. It's not the same type of error that happens when you can't build an email, deliver it, or even get a response that isn't 200. That error is a configuration issue and so the sooner we notify the user of Bamboo, the better. We can also think about it this way: we want to return an ok/error tuple because we people want to handle email building or delivery issues. Having an API key missing isn't that kind of issue. It means the library is configured incorrectly, so it seems good to raise an error.
- Loading branch information
Showing
2 changed files
with
42 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters