Skip to content

Commit

Permalink
Update README for async/await
Browse files Browse the repository at this point in the history
  • Loading branch information
Melvin Gundlach committed Jun 26, 2023
1 parent 005c4e8 commit f2d16e2
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,17 @@ import SendGrid

let email = SendGridEmail()

return req.application.sendgrid.client.send([email], on: req.eventLoop)
try await req.application.sendgrid.client.send(email)
~~~~

## Error handling
If the request to the API failed for any reason a `SendGridError` is the result
of the future, and has an `errors` property that contains an array of errors
returned by the API:

If the request to the API failed for any reason a `SendGridError` is thrown and has an `errors` property that contains an array of errors returned by the API:

~~~~swift
return req.application.sendgrid.client.send([email], on: req.eventLoop).flatMapError { error in
if let sendgridError = error as? SendGridError {
req.logger.error("\(error)")
}
// ...
do {
try await req.application.sendgrid.client.send(email)
} catch let error as SendGridError {
req.logger.error("\(error)")
}
~~~~

0 comments on commit f2d16e2

Please sign in to comment.