From f2d16e2fb856095948c132bbbceff2ec85809cad Mon Sep 17 00:00:00 2001 From: Melvin Gundlach Date: Mon, 26 Jun 2023 16:39:54 +0200 Subject: [PATCH] Update README for async/await --- README.md | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 6e99722..71242d2 100644 --- a/README.md +++ b/README.md @@ -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)") } ~~~~