You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm getting the following error when attempting to send an SMS:
Precondition failed: file /Users/wanderbit/Documents/VaporDevelopment/arframer/.build/checkouts/swift-nio/Sources/NIO/ChannelPipeline.swift, line 1447
Illegal instruction: 4
Here's my route:
app.post("sendsms") { req -> EventLoopFuture<ClientResponse> in
let sms = OutgoingSMS(body: "hi", from: "+15555555555, to: "+15555555556")
return req.twilio.send(sms)
}
I believe the issue is that this package sends an sms with application.client. Would it be better to pass in a client to the send() function so the work could be done on the request instead of the application?
The text was updated successfully, but these errors were encountered:
I believe the issue is here where we get the application's eventloopgroup even though we could be inside of a request:
public func send(_ sms: OutgoingSMS) -> EventLoopFuture<ClientResponse> {
guard let configuration = self.configuration else {
fatalError("Twilio not configured. Use app.twilio.configuration = ...")
}
return application.eventLoopGroup.future().flatMapThrowing { _ -> HTTPHeaders in
let authKeyEncoded = try self.encode(accountId: configuration.accountId, accountSecret: configuration.accountSecret)
var headers = HTTPHeaders()
headers.add(name: .authorization, value: "Basic \(authKeyEncoded)")
return headers
}.flatMap { headers in
let twilioURI = URI(string: "https://api.twilio.com/2010-04-01/Accounts/\(configuration.accountId)/Messages.json")
return self.application.client.post(twilioURI, headers: headers) {
try $0.content.encode(sms, as: .urlEncodedForm)
}
}
}
According to the Vapor docs:
Vapor expects that route closures will stay on req.eventLoop. If you hop threads, you must ensure access to Request and the final response future all happen on the request's event loop.
I think when we call application.eventLoopGroup.future() we're jumping outside of the requests event loop and causing an issue.
I'm getting the following error when attempting to send an SMS:
Here's my route:
I believe the issue is that this package sends an sms with application.client. Would it be better to pass in a client to the send() function so the work could be done on the request instead of the application?
The text was updated successfully, but these errors were encountered: